Expected to ship end of May
npm install typescript@rc
interface CredentialedUser {
id: string;
age: number;
name: string;
password: string;
}
type User = Omit(CredentialedUser, 'password');
type UserInfo = Omit(CredentialedUser, 'password' | 'id');
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
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
When composing higher-order generic functions TS 3.5 will maintain the generic T instead of using the {} type
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 {}
let dict: { [s: string]: unknown };
dict = () => {};
This change was made due to the implicit unknown in generics
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(10);
Throws when targeting ES5. Returns [] in ES6.