Inside one file, you can freely mark the number 1-9:

shift + cmd + [-]

And jump to Number of bookmark:

cmd + [-]


It helps to generate type safe interface based the json file you provided.

For example you can create a json file called pokemon.json:

{
"id": ,
"name": "Bulbasaur",
"img": "http://www.serebii.net/pokemongo/pokemon/001.png",
"type": [ "Grass", "Poison" ],
"weaknesses": [ "Fire", "Ice", "Flying", "Psychic" ]
}

Then in the file you want to generate the code, open vs cammand panel, enter "Paste Json...", enter "Pokemon"...

It will genearte type safe code and lots of utitlties code.

export interface Pokemon {
id: number;
name: string;
img: string;
type: string[];
weaknesses: string[];
} // Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export namespace Convert {
export function toPokemon(json: string): Pokemon {
return cast(JSON.parse(json), r("Pokemon"));
} export function pokemonToJson(value: Pokemon): string {
return JSON.stringify(value, null, 2);
} function cast<T>(obj: any, typ: any): T {
if (!isValid(typ, obj)) {
throw Error(`Invalid value`);
}
return obj;
} function isValid(typ: any, val: any): boolean {
if (typ === "any") { return true; }
if (typ === null) { return val === null; }
if (typ === false) { return false; }
while (typeof typ === "object" && typ.ref !== undefined) {
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) { return isValidEnum(typ, val); }
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? isValidUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? isValidArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? isValidObject(typ.props, typ.additional, val)
: false;
}
return isValidPrimitive(typ, val);
} function isValidPrimitive(typ: string, val: any) {
return typeof typ === typeof val;
} function isValidUnion(typs: any[], val: any): boolean {
// val must validate against one typ in typs
return typs.some((typ) => isValid(typ, val));
} function isValidEnum(cases: string[], val: any): boolean {
return cases.indexOf(val) !== -1;
} function isValidArray(typ: any, val: any): boolean {
// val must be an array with no invalid elements
return Array.isArray(val) && val.every((element) => {
return isValid(typ, element);
});
} function isValidObject(props: { [k: string]: any }, additional: any, val: any): boolean {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return false;
}
return Object.getOwnPropertyNames(val).every((key) => {
const prop = val[key];
if (Object.prototype.hasOwnProperty.call(props, key)) {
return isValid(props[key], prop);
}
return isValid(additional, prop);
});
} function a(typ: any) {
return { arrayItems: typ };
} function u(...typs: any[]) {
return { unionMembers: typs };
} function o(props: { [k: string]: any }, additional: any) {
return { props, additional };
} function m(additional: any) {
return { props: {}, additional };
} function r(name: string) {
return { ref: name };
} const typeMap: any = {
"Pokemon": o({
id: 0,
name: "",
img: "",
type: a(""),
weaknesses: a(""),
}, false),
};
}

  

A easy way to dealing with Git.

Good for demoing the code in a team.

[Tools] VS Code Tips的更多相关文章

  1. Visual Studio Code Tips

    新项目要用到Visual Studio Code, 在使用的过程中有些tips, 记录下来以便查阅. 1. 自动保存代码 文件 => 自动保存 2. 帮助输入代码模式 扩展 => 安装HT ...

  2. SQL Server Code tips (持续更新)

    1.  表存在,查询语句也能执行,但是表名下面总是有条红线,说对象名无效 CTRL + SHIFT +R  刷新本地缓存就可以了 2. IDE (Integrated Development Envi ...

  3. [notes] some code tips

    genericizing-codehtml, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin ...

  4. maven 编译出现初始化异常:com/sun/tools/javac/code/TypeTags

    使用的式jdk11 lombok式1.16.4 错误原因:版本不匹配 升级lombok到1.18.4 问题解决

  5. php之code tips

    使用list来实现一次获取explode后的特定段值: list( , $mid) = explode(';', $string); 使用NULL === 来代替is_null: is_null和 N ...

  6. android xmlns:tools用法

    一开始不明白,后来删掉这个属性之后发现会出现一个提示: pick preview layout from the "Fragment Layout" context menu 原来 ...

  7. Android code wiki

    Android code wiki Tip1: 类的全局静态变量的使用,这样可以静态变量只分配一次内存,可以不通过类的对象也就是可以通过类名直接使用该变量.(使用场景:Request_Code ,Re ...

  8. Android 之 tools:context和tools:ignore两个属性的作用

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  9. visual code golang配置

    前言 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org), 导致一些包无法安装,最终会导致环境搭建失败,跟据这个教程几步,我们将可以快速的构建golang ...

随机推荐

  1. IE版本的判断

    var Sys = {};var ua = navigator.userAgent.toLowerCase(); var s;(s = ua.match(/msie ([\d.]+)/)) ? Sys ...

  2. HTML-ul分分钟理解

    在HTML中,列表有三种,如图分别是有序.无序和自定义列表.上面是我在网络上找到的一张图片很明了就看以看出来,今天要分享的就是其中的无序列表Ul(unordered list),给大家整理了一下我所知 ...

  3. Linux下MySql数据的导入导出

    1,每天4点备份mysql数据: 2,为节省空间,删除超过3个月的所有备份数据: 3,删除超过7天的备份数据,保留3个月里的 10号 20号 30号的备份数据: mysqldump -u用戶名 -p密 ...

  4. celery定时执行ansible api返回为空的问题

    有两种方法解决这个问题,就是关闭assert:1.在celery 的worker启动窗口设置export PYTHONOPTIMIZE=1或打开celery这个参数-O OPTIMIZATION2.注 ...

  5. 设置靠近 水平居中的主体内容Div 的 左侧位置固定的Div

    示例效果: 1.主体内容的divMain 水平居中: 2.divLeft 靠近divMain ,位置固定,不随垂直滚动条而动: 相关代码: <html> <head runat=&q ...

  6. dedecms:解析Robots.txt 协议标准

    Robots.txt 是存放在站点根目录下的一个纯文本文件.虽然它的设置很简单,但是作用却很强大.它可以指定搜索引擎蜘蛛只抓取指定的内容,或者是禁止搜索引擎蜘蛛抓取网站的部分或全部内容. 下面我们就来 ...

  7. oracle 用户的操作

    语法: CREATE USER user   IDENTIFIED { BY password              | EXTERNALLY [ AS 'certificate_DN' ]    ...

  8. 使用whIle循环语句和变量打印九九乘法表

    -设置i变量declare @i int --设置j变量declare @j int --设置乘法表变量declare @chengfabiao varchar(1000)--给i,j,@chengf ...

  9. utf-8与unicode是什么关系

    简单来说: Unicode  is a charset. ------Unicode 他就是一个字符集 UTF-8 is encoding style. --------UTF-8他就是一种编码方式, ...

  10. Ubuntu 18.04 安装chrome浏览器

    参考 https://blog.csdn.net/cyem1/article/details/86297197 一分钟安装教程! 1.将下载源加入到系统的源列表(添加依赖) sudo wget htt ...