TypeScript 3.5

Hello!

Paul Shannon

TypeScript 3.5 RC

Expected to ship end of May

npm install typescript@rc

Speed Improvements

  • Fixed a regression from TS 3.4
  • 3.5 is faster in many cases than 3.3
  • --incremental improvements

Omit Helper


				interface CredentialedUser {
					id: string;
					age: number;
					name: string;
					password: string;
				}

				type User = Omit(CredentialedUser, 'password');

				type UserInfo = Omit(CredentialedUser, 'password' | 'id');
			

Improved Union Type Checking

excess union member checks


				interface Point {
					x: number;
					y: number;
				}

				interface Label {
					name: string;
				}

				const value: Point | Label = {
					x: 0,
					y: 0,
					name: true
				}
			

TS 3.5 checks all excess members for valid typing

smarter union type checking


				type S = { done: boolean, value: number }
				type T =
					{ done: false, value: number }
					| { done: true, value: number };

				declare let source: S;
				declare let target: T;

				target = source;
			

TS 3.5 will combine constituent types to match unions when appropriate

Higher order type inference from generic constructors

When composing higher-order generic functions TS 3.5 will maintain the generic T instead of using the {} type

Breaking Changes Improvements

generic type parameters are implicitly constrained to unknown


				function foo<T>(x: T): [T, string] {
						return [x, x.toString()]
						// error! Property 'toString' does not exist on type 'T'.
					}
			

If {} is the desired default then use T extend {}

{ [k: string]: unknown } is no longer a wildcard assignment target


				let dict: { [s: string]: unknown };

				dict = () => {};
			

This change was made due to the implicit unknown in generics

Fixes to unsound writes to indexed access types


				type A = {
					s: string;
					n: number;
				};

				function write<K extends keyof A>(arg: A, key: K, value: A[K]): void {
					arg[key] = "hello, world";
				}

				// Breaks the object by putting a string where a number should be
				write(a, "n", "oops!");
			

Object.keys rejects primitives in ES5


				Object.keys(10);
			

Throws when targeting ES5. Returns [] in ES6.