class Message { public time: string public content: string = '' publictype: number public user: User | null constructor (time: string, content: string, type: number, user: User | null) { this.time = time this.content = content this.type = type this.user = user } }
忽略错误
1 2 3 4 5 6 7 8
// 单行忽略 @ts-ignore
// 忽略全文 @ts-nocheck
// 取消忽略全文 @ts-check
后端node使用TypeScript
需创建tsconfig.json
1 2 3 4 5 6 7 8 9
{ "compilerOptions": { /* BasicOptions */ "target": "es5", /* SpecifyECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019'or'ESNEXT'. */ "module": "commonjs", /* Specifymodule code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or'ESNext'. */ "outDir": "./build", /* Redirect output structure to the directory. */ "esModuleInterop": true /* Enables emit interoperability between CommonJSandESModules via creation of namespace objects for all imports. Implies'allowSyntheticDefaultImports'. */ } }