Reputation: 114805
A friend refactored some code and moved the definition of a variable called name
from the function's top-level scope into a then
's body. This variable was used in a subsequent then
which caused a ReferenceError since name
was not in scope.
We couldn't understand how the code passed compilation until we saw that typescript/lib.d.ts has the following deceleration:
declare const name: never;
Long story short, I have two questions.
name
(as well as length
and many other globals) added by default to typescript?Upvotes: 9
Views: 1959
Reputation: 16876
This seems to be a very old browser behaviour. Referring to the MDN both name
and length
are properties of the window
object.
In order to get rid of all the DOM-specific declarations, you can set the lib
property in your tsconfig
accordingly. You cann see all options on this page. Take a look at the --lib
flag.
An option to tell TypeScript your code runs on Node.JS would be nice. But it seems not yet implemented: https://github.com/Microsoft/TypeScript/issues/9466
Upvotes: 12