More tests

This commit is contained in:
Anders Hejlsberg 2016-11-11 11:00:09 -08:00
parent e9b6ddc9ae
commit ca3f797832
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,62 @@
// @strictNullChecks: true
// @declaration: true
type Partial<T> = {
[P in keyof T]?: T[P];
};
type Readonly<T> = {
readonly [P in keyof T]: T[P];
};
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
}
type Record<K extends string | number, T> = {
[_ in K]: T;
}
interface Shape {
name: string;
width: number;
height: number;
visible: boolean;
}
interface Named {
name: string;
}
interface Point {
x: number;
y: number;
}
type T00 = { [P in P]: string }; // Error
type T01 = { [P in Date]: number }; // Error
type T02 = Record<Date, number>; // Error
type T10 = Pick<Shape, "name">;
type T11 = Pick<Shape, "foo">; // Error
type T12 = Pick<Shape, "name" | "foo">; // Error
type T13 = Pick<Shape, keyof Named>;
type T14 = Pick<Shape, keyof Point>; // Error
type T15 = Pick<Shape, never>;
type T16 = Pick<Shape, undefined>;
function f1<T>(x: T) {
let y: Pick<Shape, T>; // Error
}
function f2<T extends string | number>(x: T) {
let y: Pick<Shape, T>; // Error
}
function f3<T extends keyof Shape>(x: T) {
let y: Pick<Shape, T>;
}
function f4<T extends keyof Named>(x: T) {
let y: Pick<Shape, T>;
}

View File

@ -26,6 +26,15 @@ type T36 = { [P in keyof void]: void };
type T37 = { [P in keyof symbol]: void };
type T38 = { [P in keyof never]: void };
type T40 = { [P in string]: void };
type T41 = { [P in number]: void };
type T42 = { [P in string | number]: void };
type T43 = { [P in "a" | "b" | 0 | 1]: void };
type T44 = { [P in "a" | "b" | "0" | "1"]: void };
type T45 = { [P in "a" | "b" | "0" | "1" | 0 | 1]: void };
type T46 = { [P in number | "a" | "b" | 0 | 1]: void };
type T47 = { [P in string | number | "a" | "b" | 0 | 1]: void };
declare function f1<T1>(): { [P in keyof T1]: void };
declare function f2<T1 extends string>(): { [P in keyof T1]: void };
declare function f3<T1 extends number>(): { [P in keyof T1]: void };