让我说我有这些文件:
// foo.d.ts
declare global {
interface Console {
foo: string
}
}
// foo.js
console.foo = 'bar';
如何限制global augmentation仅在导入文件foo.js时适用?
// abc.js
require('./foo')
console.foo // should be OK with TS
// Which it is.
// xyz.js
console.foo // should not be OK with TS.
// But TS says that console.foo is defined as a string.
我目前依靠VSCode的默认打字稿集成,并且所有文件在文件的开头都带有//@ts-check
标志。