在打字稿中,有没有办法防止对内置函数和全局变量的隐式依赖
in typescript, is there a way to prevent implicit dependencies on builtin functions and globals
如果我在没有显式导入的情况下使用任何内置函数或全局变量,我的打字稿编译器或 eslinter 会引发错误,我会喜欢它。
可以这样做吗?如果可以,怎么做?
例如
//missing: import { console, process, Array } from "?"
export function print(): number[] {
console.log("Hello") //this console usage should raise an error
process.stdout.write("World!") //this process usage too
return new Array<number>() //ideally this Array constructor too
}
https://www.typescriptlang.org/tsconfig#noLib
Disables the automatic inclusion of any library files. If this option is set, lib is ignored.
TypeScript cannot compile anything without a set of interfaces for key primitives like: Array, Boolean, Function, IArguments, Number, Object, RegExp, and String. It is expected that if you use noLib you will be including your own type definitions for these.
如果我在没有显式导入的情况下使用任何内置函数或全局变量,我的打字稿编译器或 eslinter 会引发错误,我会喜欢它。 可以这样做吗?如果可以,怎么做?
例如
//missing: import { console, process, Array } from "?"
export function print(): number[] {
console.log("Hello") //this console usage should raise an error
process.stdout.write("World!") //this process usage too
return new Array<number>() //ideally this Array constructor too
}
https://www.typescriptlang.org/tsconfig#noLib
Disables the automatic inclusion of any library files. If this option is set, lib is ignored.
TypeScript cannot compile anything without a set of interfaces for key primitives like: Array, Boolean, Function, IArguments, Number, Object, RegExp, and String. It is expected that if you use noLib you will be including your own type definitions for these.