Closed AnglusWang closed 9 months ago
{ "compilerOptions": { "target": "ES2020", "module": "ES2020", "outDir": "dist", "strict": true, }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] }
举例来说,Web 网页开发经常会对windows对象和document对象添加自定义属性,但是 TypeScript 会报错,因为原始定义没有这些属性。解决方法就是把自定义属性写成 interface,合并进原始定义。
windows
document
interface Document { foo: string; }
document.foo = 'hello';
* 编译报错信息
error TS2339: Property 'foo' does not exist on type 'Document'.
官方 playground 正常
document.foo = 'hello';
error TS2339: Property 'foo' does not exist on type 'Document'.