The compiler's functionality is determined by the specific lib you designate for it to use.
You can control which lib the compiler utilizes in two ways: through the target
and lib
compiler options.
As described in the link above:
If --lib is not specified, a default library will be included. The default
libraries injected are:
► For --target ES5: DOM,ES5,ScriptHost
► For
--target ES6: DOM,ES6,DOM.Iterable,ScriptHost
All the different libs can be found as part of the project.
If you're aiming at es3
or es5
, then features like Number.isInteger()
cannot be used since it's considered an exclusive feature of es6
.
If you have a polyfill available, you can still target es5
by including the es6
lib:
--target es5 --lib DOM,ES6,ScriptHost
Alternatively, you can manually insert the definition from lib.es6.d.ts:
interface NumberConstructor {
isInteger(number: number): boolean;
}
The reason behind being able to utilize keywords like let
, const
, for/of
regardless of the target is that the compiler has mechanisms in place to generate equivalent code even when the feature isn't supported for the selected target.
For instance:
const arr = [1, 2, 3];
for (let num of arr) {}
Will be compiled to:
var arr = [1, 2, 3];
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
var num = arr_1[_i];
}
If no target is specified.
As seen, const
and let
get converted into var
, and for/in
turns into a standard for
loop.
Number.isInteger()
presents a different scenario, being a feature absent in certain targets such as Promise
and 'Symbol`.
The burden of adding the polyfill rests on you, alongside informing the compiler about its presence.