Reputation: 5396
I would like it if my typescript compiler or eslinter raises an error if I use any builtin function or global variable without importing it explicitly. Can this be done and if so, how?
for example
//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
}
Upvotes: 0
Views: 409
Reputation: 1566
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.
Upvotes: 5