在打字稿中,有没有办法防止对内置函数和全局变量的隐式依赖

Coe*_*oen 0 dependencies built-in compiler-warnings typescript eslint

如果我使用任何内置函数或全局变量而不显式导入它,我希望我的打字稿编译器或 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
}
Run Code Online (Sandbox Code Playgroud)

Eli*_*ias 5

https://www.typescriptlang.org/tsconfig#noLib

禁用任何库文件的自动包含。如果设置此选项,则忽略 lib。

如果没有一组关键基元的接口,例如数组、布尔值、函数、IArguments、数字、对象、RegExp 和字符串,TypeScript 就无法编译任何内容。预计如果您使用 noLib,您将包含您自己的类型定义。