Add tests

This commit is contained in:
Anders Hejlsberg 2016-12-14 14:59:10 -08:00
parent f58e1a2b17
commit 6cd7454a9b
2 changed files with 30 additions and 1 deletions

View file

@ -125,3 +125,9 @@ c.setState({ });
c.setState(foo);
c.setState({ a: undefined }); // Error
c.setState({ c: true }); // Error
type T2 = { a?: number, [key: string]: any };
let x1: T2 = { a: 'no' }; // Error
let x2: Partial<T2> = { a: 'no' }; // Error
let x3: { [P in keyof T2]: T2[P]} = { a: 'no' }; // Error

View file

@ -1,4 +1,5 @@
// @strictNullChecks: true
// @noimplicitany: true
type T = { a: number, b: string };
type TP = { a?: number, b?: string };
@ -74,4 +75,26 @@ var b04: Readonly<BP>;
var b04: Partial<Readonly<B>>;
var b04: Readonly<Partial<B>>;
var b04: { [P in keyof BPR]: BPR[P] }
var b04: Pick<BPR, keyof BPR>;
var b04: Pick<BPR, keyof BPR>;
type Foo = { prop: number, [x: string]: number };
function f1(x: Partial<Foo>) {
x.prop; // ok
(x["other"] || 0).toFixed();
}
function f2(x: Readonly<Foo>) {
x.prop; // ok
x["other"].toFixed();
}
function f3(x: Boxified<Foo>) {
x.prop; // ok
x["other"].x.toFixed();
}
function f4(x: { [P in keyof Foo]: Foo[P] }) {
x.prop; // ok
x["other"].toFixed();
}