简体   繁体   English

如何将 json 文件键入为 tsconfig.json 和 package.Z466DEEC76ECDF5FCA6D38571F632

[英]How to type json files as tsconfig.json and package.json

I noticed that some json files with specific names get intellisense, like:我注意到一些具有特定名称的 json 文件得到了智能感知,例如:

  1. tsconfig.json
  2. jsconfig.json
  3. package.json
  4. .eslintrc.json
  5. .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的一个很好的介绍

here is a screenshot这是一个截图在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我将 tsconfig.json 中的“模块”更改为“ESNext”并将 package.json 中的“类型”更改为“模块”时,出现错误 - When I change "module" in tsconfig.json to 'ESNext' and "type" in package.json to 'module', I get an error tsconfig.json - 扩展 - 编译器不使用其他 tsconfig.json 文件 - tsconfig.json - extends - compiler not using other tsconfig.json files tsconfig.json 的目的是什么? - what is the purpose of tsconfig.json? 为什么 TypeScript 编译器会忽略 tsconfig.json? - Why is the TypeScript compiler ignoring tsconfig.json? 在配置文件 tsconfig.json 中找不到输入 - No input was found in config file tsconfig.json TypeScript tsconfig.json 中的路径别名未找到 - TypeScript path aliases in tsconfig.json not found 为什么普通的 json 文件不允许评论,而 tsconfig.json 允许评论? - Why normal json files don't allow comments where as tsconfig.json allow comment? Visual Studio Code - 类型脚本 - 无法加载 tsconfig.json 和 packages.json 架构 - Visual Studio Code - Type Script - Unable to load tsconfig.json and packages.json schemas 一段时间后 package.json 文件已损坏 - The package.json files are corrupted after a while Typescript类型定义-如何在当前package.json中全部安装? - Typescript type definitions - How to install all in current package.json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM