How compatible (will it be) TypeScript with ES6 (ECMAScript 2015)

I thought TypeScript is (mostly) ECMAScript 6 (aka. 2015) with additional type annotations.

My TypeScript compiler (1.6.2) complains about the following code:

if (calc.distance > Number.EPSILON) {
    ...
}

error TS2339: property 'EPSILON' does not exist in type 'NumberConstructor'.

Is there a type problem or is TypeScript still not a superset of ES6?

I have not tried such things as Map, WeakMap, Promises, generators, ...

Is TypeScript a bit behind ES6 or is it maybe going in the other direction? Should I run TypeScript compiler output through Babel?

Just started with TypeScript, and I don't want to go back to the wrong horse.

+4
2

Number.EPSILON ES3 ES5

, TypeScript ( ) ECMAScript 6 (aka. 2015) .

TypeScript - ECMAScript . ES6, , , lambdas, for of, let, ES5 ES3, . API , ( Babel Traceur).

ES6.

ES3 ES5 : 1/ a polyfill ( ) 2/ TypeScript.

TypeScript API ES6

, . , API ES6.

API ES6 . . node lib/node_modules/typescript/lib/lib.es6.d.ts. EPSILON. NumberConstructor. (TS 1.6.2): ​​

interface NumberConstructor {
    /**
      * The value of Number.EPSILON is the difference between 1 and the smallest value greater than 1
      * that is representable as a Number value, which is approximately:
      * 2.2204460492503130808472633361816 x 10‍−‍16.
      */
    EPSILON: number;

    /**
      * Returns true if passed value is finite.
      * Unlike the global isFininte, Number.isFinite doesn't forcibly convert the parameter to a
      * number. Only finite values of the type number, result in true.
      * @param number A numeric value.
      */
    isFinite(number: number): boolean;

    /**
      * Returns true if the value passed is an integer, false otherwise.
      * @param number A numeric value.
      */
    isInteger(number: number): boolean;

    /**
      * Returns a Boolean value that indicates whether a value is the reserved value NaN (not a
      * number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter
      * to a number. Only values of the type number, that are also NaN, result in true.
      * @param number A numeric value.
      */
    isNaN(number: number): boolean;

    /**
      * Returns true if the value passed is a safe integer.
      * @param number A numeric value.
      */
    isSafeInteger(number: number): boolean;

    /**
      * The value of the largest integer n such that n and n + 1 are both exactly representable as
      * a Number value.
      * The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1.
      */
    MAX_SAFE_INTEGER: number;

    /**
      * The value of the smallest integer n such that n and n − 1 are both exactly representable as
      * a Number value.
      * The value of Number.MIN_SAFE_INTEGER is −9007199254740991 (−(2^53 − 1)).
      */
    MIN_SAFE_INTEGER: number;

    /**
      * Converts a string to a floating-point number.
      * @param string A string that contains a floating-point number.
      */
    parseFloat(string: string): number;

    /**
      * Converts A string to an integer.
      * @param s A string to convert into a number.
      * @param radix A value between 2 and 36 that specifies the base of the number in numString.
      * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
      * All other strings are considered decimal.
      */
    parseInt(string: string, radix?: number): number;
}

.

+4

:

interface INumber {
    EPSILON: any
}
declare var Number: INumber;
0

Source: https://habr.com/ru/post/1610403/


All Articles