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. ckeditor 工具栏的配置

    config.toolbar =    [       ['Undo','Redo'],            ['Font','FontSize'],            ['Bold','Ita ...

  2. day24 03 多继承

    day24 03 多继承 正常的代码中  单继承==减少了代码的重复 继承表达的是一种 子类是父类的关系 1.简单的多继承关系 A,B,C,D四个类,其中D类继承A,B,C三个父类,因此也叫多继承,子 ...

  3. Android json 数据解析

    1.json格式 2.json解析 3.gson解析 4.fastjson解析 一.Json格式 json一种轻量级的数据交换格式.在网络上传输交换数据一般用xml, json. 两种结构: 1)对象 ...

  4. 如何卸载系统自带的Microsoft Office

    (1)首先.在C盘删除office文件夹. (2)删除注册表 1)开始菜单-->运行-->regedit进入注册表 (window+r  -->) 2)在注册表里找到HKEY_CUR ...

  5. React Native常用组件在Android和IOS上的不同

    React Native常用组件在Android和IOS上的不同 一.Text组件在两个平台上的不同表现 1.1 height与fontSize 1.1.1只指定font,不指定height 在这种情 ...

  6. React Native导航器Navigator

    React Native导航器Navigator 使用导航器可以让你在应用的不同场景(页面)间进行切换.导航器通过路由对象来分辨不同的场景.利用renderScene方法,导航栏可以根据指定的路由来渲 ...

  7. Linux 信息查询

    CPU信息查看 #查看CPU型号:   $>grep 'model name' /proc/cpuinfo |uniq    model name : Intel(R) Xeon(R) CPU ...

  8. JS高级——Object.prototype成员

    基本概念 成员 描述 Object.prototype.__proto__ 指向当对象被实例化的时候,用作原型的对象. Object.prototype.hasOwnProperty() 返回一个布尔 ...

  9. 易语言 打开exe可执行文件、打开网页

    打开文件--------按钮被单击事件 直接复制以下代码即可 .版本 2 .子程序 _按钮58_被单击 运行 (“exe文件路径”, 假, ) 打开网站--------按钮被单击事件 直接复制以下代码 ...

  10. 通过PHP怎样取到android系统下apk应用的包名,版本号等信息

    公司项目关系,要求在通过PHP解析android系统应用apk包内的一切可用的信息.比如说:APK包名,版本号,版本名,安装权限等一系列关于对应包的信息.通过google查找相关的解决方案,都没有找到 ...