These changes list where implementation differs between versions as the spec and compiler are simplified and inconsistencies are corrected.
For breaking changes to the compiler/services API, please check the [[API Breaking Changes]] page.
For full list of breaking changes see the breaking change issues.
Entry point of TypeScript npm package was moved from bin to lib to unblock scenarios when 'node_modules/typescript/bin/typescript.js' is served from IIS (by default bin is in the list of hidden segments so IIS will block access to this folder).
In accordance with the ES6 spec, module bodies are now parsed in strict mode. module bodies will behave as if "use strict" was defined at the top of their scope; this includes flagging the use of arguments and eval as variable or parameter names, use of future reserved words as variables or parameters, use of octal numeric literals, etc..
The compiler uses the new bulk-export variation of the _export function in the System module format that takes any object containing key value pairs (optionally an entire module object for export *) as arguments instead of key, value.
The module loader needs to be updated to v0.17.1 or higher.
It is an error to specify properties in an object literal that were not specified on the target type, when assigned to a variable or passed for a parameter of a non-empty target type.
Example:
var x: { foo: number };
x = { foo: 1, baz: 2 }; // Error, excess property `baz`
var y: { foo: number, bar?: number };
y = { foo: 1, baz: 2 }; // Error, excess or misspelled property `baz`Recommendations:
To avoid the error, either define a indexer on the target type or use type assertion on the object literal in question.
var x: { foo: number, [x: string]: any };
x = { foo: 1, baz: 2 }; // Ok, `baz` matched by index signatureinterface Foo {
foo: number;
}
interface Bar extends Foo {
bar: number;
}
var y: Foo;
y = <Bar>{ foo: 1, bar: 2 };Function and class default export declarations can no longer merge with entities intersecting in their meaning
Declaring an entity with the same name and in the same space as a default export declaration is now an error; for example,
export default function foo() {
}
namespace foo {
var x = 100;
}and
export default class Foo {
a: number;
}
interface Foo {
b: string;
}both cause an error.
However, in the following example, merging is allowed because the namespace does does not have a meaning in the value space:
export default class Foo {
}
namespace Foo {
}Recommendations:
Declare a local for your default export and use a separate export default statement as so:
class Foo {
a: number;
}
interface foo {
b: string;
}
export default Foo;For more details see the originating issue.
For full list of breaking changes see the breaking change issues.
This is an alignment with the ES6 semantics of arrow functions. Previously arguments within an arrow function would bind to the arrow function arguments. As per ES6 spec draft 9.2.12, arrow functions do not have an arguments objects. In TypeScript 1.5, the use of arguments object in arrow functions will be flagged as an error to ensure your code ports to ES6 with no change in semantics.
Example:
function f() {
return () => arguments; // Error: The 'arguments' object cannot be referenced in an arrow function.
}Recommendations:
// 1. Use named rest args
function f() {
return (...args) => { args; }
}
// 2. Use function expressions instead
function f() {
return function(){ arguments; }
}For regular enums, pre 1.5, the compiler only inline constant members, and a member was only constant if its initializer was a literal. That resulted in inconsistent behavior depending on whether the enum value is initalized with a literal or an expression. Starting with Typescript 1.5 all non-const enum members are not inlined.
Example:
var x = E.a; // previously inlined as "var x = 1; /*E.a*/"
enum E {
a = 1
}Recommendation:
Add the const modifier to the enum declaration to ensure it is consistently inlined at all consumption sites.
For more details see issue #2183.
Prior to this release, contextual types did not flow through parenthesized expressions. This has forced explicit type casts, especially in cases where parentheses are required to make an expression parse.
In the examples below, m will have a contextual type, where previously it did not.
var x: SomeType = (n) => ((m) => q);
var y: SomeType = t ? (m => m.length) : undefined;
class C extends CBase<string> {
constructor() {
super({
method(m) { return m.length; }
});
}
}See issues #1425 and #920 for more details.
TypeScript 1.5 refreshes the DOM types in lib.d.ts. This is the first major refresh since TypeScript 1.0; many IE-specific definitions have been removed in favor of the standard DOM definitions. as well as adding missing types like Web Audio and touch events.
Workaround:
You can keep using older versions of the library with newer version of the compiler. You will need to include a local copy of a previous version in your project. Here is the last released version before this change (TypeScript 1.5-alpha).
Here is a list of changes:
- Property
selectionis removed from typeDocument - Property
clipboardDatais removed from typeWindow - Removed interface
MSEventAttachmentTarget - Properties
onresize,disabled,uniqueID,removeNode,fireEvent,currentStyle,runtimeStyleare removed from typeHTMLElement - Property
urlis removed from typeEvent - Properties
execScript,navigate,itemare removed from typeWindow - Properties
documentMode,parentWindow,createEventObjectare removed from typeDocument - Property
parentWindowis removed from typeHTMLDocument - Property
setCapturedoes not exist anywhere now - Property
releaseCapturedoes not exist anywhere now - Properties
setAttribute,styleFloat,pixelLeftare removed from typeCSSStyleDeclaration - Property
selectorTextis removed from typeCSSRule CSSStyleSheet.rulesis of typeCSSRuleListinstead ofMSCSSRuleListdocumentElementis of typeElementinstead ofHTMLElementEventhas a new required propertyreturnValueNodehas a new required propertybaseURIElementhas a new required propertyclassListLocationhas a new required propertyorigin- Properties
MSPOINTER_TYPE_MOUSE,MSPOINTER_TYPE_TOUCHare removed from typeMSPointerEvent CSSStyleRulehas a new required propertyreadonly- Property
execUnsafeLocalFunctionis removed from typeMSApp - Global method
toStaticHTMLis removed HTMLCanvasElement.getContextnow returnsCanvasRenderingContext2D | WebGLRenderingContex- Removed extension types
Dataview,Weakmap,Map,Set XMLHttpRequest.sendhas two overloadssend(data?: Document): void;andsend(data?: String): void;window.orientationis of typestringinstead ofnumber- IE-specific
attachEventanddetachEventare removed fromWindow
Here is a list of libraries that are partly or entirely replaced by the added DOM types:
DefinitelyTyped/auth0/auth0.d.tsDefinitelyTyped/gamepad/gamepad.d.tsDefinitelyTyped/interactjs/interact.d.tsDefinitelyTyped/webaudioapi/waa.d.tsDefinitelyTyped/webcrypto/WebCrypto.d.ts
For more details, please see the full change.
In accordance with the ES6 spec, class bodies are now parsed in strict mode. Class bodies will behave as if "use strict" was defined at the top of their scope; this includes flagging the use of arguments and eval as variable or parameter names, use of future reserved words as variables or parameters, use of octal numeric literals, etc..
For full list of breaking changes see the breaking change issues.
See issue #868 for more details about breaking changes related to Union Types
Given multiple viable candidates from a Best Common Type computation we now choose an item (depending on the compiler's implementation) rather than the first item.
var a: { x: number; y?: number };
var b: { x: number; z?: number };
// was { x: number; z?: number; }[]
// now { x: number; y?: number; }[]
var bs = [b, a]; This can happen in a variety of circumstances. A shared set of required properties and a disjoint set of other properties (optional or otherwise), empty types, compatible signature types (including generic and non-generic signatures when type parameters are stamped out with any).
Recommendation Provide a type annotation if you need a specific type to be chosen
var bs: { x: number; y?: number; z?: number }[] = [b, a];Using different types for multiple arguments of type T is now an error, even with constraints involved:
declare function foo<T>(x: T, y:T): T;
var r = foo(1, ""); // r used to be {}, now this is an errorWith constraints:
interface Animal { x }
interface Giraffe extends Animal { y }
interface Elephant extends Animal { z }
function f<T extends Animal>(x: T, y: T): T { return undefined; }
var g: Giraffe;
var e: Elephant;
f(g, e);See microsoft/TypeScript#824 (comment) for explanation.
Recommendations Specify an explicit type parameter if the mismatch was intentional:
var r = foo<{}>(1, ""); // Emulates 1.0 behavior
var r = foo<string|number>(1, ""); // Most useful
var r = foo<any>(1, ""); // Easiest
f<Animal>(g, e);or rewrite the function definition to specify that mismatches are OK:
declare function foo<T,U>(x: T, y:U): T|U;
function f<T extends Animal, U extends Animal>(x: T, y: U): T|U { return undefined; }You cannot use heterogeneous argument types anymore:
function makeArray<T>(...items: T[]): T[] { return items; }
var r = makeArray(1, ""); // used to return {}[], now an errorLikewise for new Array(...)
Recommendations Declare a back-compat signature if the 1.0 behavior was desired:
function makeArray<T>(...items: T[]): T[];
function makeArray(...items: {}[]): {}[];
function makeArray<T>(...items: T[]): T[] { return items; }var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
var r9 = f10('', () => (a => a.foo), 1); // r9 was any, now this is an errorRecommendations Manually specify a type parameter
var r9 = f10<any>('', () => (a => a.foo), 1);ECMAScript 2015 Language Specification (ECMA-262 6th Edition) specifies that ClassDeclaration and ClassExpression are strict mode productions. Thus, additional restrictions will be applied when parsing a class declaration or class expression.
Examples:
class implements {} // Invalid: implements is a reserved word in strict mode
class C {
foo(arguments: any) { // Invalid: "arguments" is not allow as a function argument
var eval = 10; // Invalid: "eval" is not allowed as the left-hand-side expression
arguments = []; // Invalid: arguments object is immutable
}
}For complete list of strict mode restrictions, please see Annex C - The Strict Mode of ECMAScript of ECMA-262 6th Edition.
For full list of breaking changes see the breaking change issues.
Examples:
var ResultIsNumber17 = +(null + undefined);
// Operator '+' cannot be applied to types 'undefined' and 'undefined'.
var ResultIsNumber18 = +(null + null);
// Operator '+' cannot be applied to types 'null' and 'null'.
var ResultIsNumber19 = +(undefined + undefined);
// Operator '+' cannot be applied to types 'undefined' and 'undefined'.Similarly, using null and undefined directly as objects that have methods now is an error
Examples:
null.toBAZ();
undefined.toBAZ();