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. Swagger 教程

    转自   Vojtech Ruzicka的编程博客 (一)Swagger和SpringFox 记录REST API非常重要.它是一个公共接口,其他模块,应用程序或开发人员可以使用它.即使你没有公开曝光 ...

  2. asp.net core 2.0 Json结果的格式

    asp.net core 2.0 默认返回的结果格式是Json, 并使用json.net对结果默认做了camel case的转化(大概可理解为首字母小写). 这一点与老.net web api 不一样 ...

  3. Codeforces 792D

    题意:给定一棵拥有n个节点的满二叉树(即n==2^x-1),q个查询,每次给出一个节点的编号,再给出一个由L,R,U组成的字符串序列,依次表示向左子节点.右子节点.父节点移动,如果移动不合法,则忽略. ...

  4. CF 351A - Jeff and Rounding DP

    http://codeforces.com/problemset/problem/351/C 题意:有2*n个浮点数a1,a2,a3...a2*n,把他们分成n队,对于每对<A,B>,对A ...

  5. Mac下CUDA开启及Tensorflow-gpu 1.4 安装

    本文由@ray 出品,转载请注明出处.  文章链接:http://www.cnblogs.com/wolfray/p/8040694.html 在之前的文章中,笔者介绍了在Mac下安装Tensorfl ...

  6. JS高级——原型链

    构造函数 构造函数是特殊的函数,里面没有returen返回值 new的过程中,会自动将对象返回,不需要return new的过程中,会执行函数中的代码,会将创建的对象赋值给构造函数中的this 基本概 ...

  7. jQuery——jQuery选择器

    基本选择器 # Id选择器 $(“#btnShow”)选择id为btnShow的一个元素 . 类选择器 $(“.liItem”)选择含有类liItem的所有元素 ele 标签选择器 $(“li”)选择 ...

  8. SQL基本操作——COVERT

    CONVERT() 函数是把日期转换为新数据类型的通用函数.CONVERT() 函数可以用不同的格式显示日期/时间数据. --语法 CONVERT(data_type(length),data_to_ ...

  9. vim下阅读代码时标签跳转设置

    1.在fedora14中的 /etc/vimrc下,加入如下几行,可根据源代码工程文件的结构来定 2. 在源代码工程内,输入如下命令 ctags -R 当前目录下将生成一个tags文件 3.查看源代码 ...

  10. Free中的buffer和cache理解

    吐血推荐文章: Linux内存中的Cache真的能被回收么? free中的buffer和cache: redhat对free输出的解读 两者都是RAM中的数据.简单来说,buffer是即将要被写入磁盘 ...