[Tools] VS Code Tips
Inside one file, you can freely mark the number 1-9:
shift + cmd + [1-9]
And jump to Number of bookmark:
cmd + [1-9]
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": 1, "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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2016-07-05 [React] Using the classnames library for conditional CSS
2016-07-05 [React] Creating a Stateless Functional Component