[英]How to type json files as tsconfig.json and package.json
I noticed that some json files with specific names get intellisense, like:我注意到一些具有特定名称的 json 文件得到了智能感知,例如:
tsconfig.json
jsconfig.json
package.json
.eslintrc.json
.prettierrc.json
Some screenchots一些截图
[ [
]
]
[ [
]
]
how can i type the schema of my own json files is it declares as a json module or something similar?我如何输入我自己的 json 文件的架构,它是声明为 json 模块还是类似的东西?
just create a person.model.ts
file that carries your json interface then export the interface from the file in which is defined只需创建一个带有 json 接口的
person.model.ts
文件,然后从定义的文件中导出接口
interface Person{
name: string;
age: number;
}
then import it wherever you want to use it然后将其导入任何您想使用的地方
import Person from "./person.model.ts"
then use it as a type for your json然后将其用作 json 的类型
let p:Person = {
name: 'Joe',
age: 20
}
also your editor/IDE will guide you with the missing types and will throw an error if you entered a wrong property like that此外,您的编辑器/IDE 将指导您使用缺少的类型,如果您输入了这样的错误属性,则会引发错误
I already found that the json Schemas are based on the json-schema.org that would enable intellisense for json files我已经发现 json 架构基于json-schema.org可以为 json 文件启用智能感知
here is a good intro for defining your own json schema https://json-schema.org/understanding-json-schema/basics.html这是定义您自己的 json 架构https://json-schema.org/understanding-json-schema/basics.html的一个很好的介绍
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.