mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
More tests
This commit is contained in:
parent
e9b6ddc9ae
commit
ca3f797832
62
tests/cases/conformance/types/mapped/mappedTypeErrors.ts
Normal file
62
tests/cases/conformance/types/mapped/mappedTypeErrors.ts
Normal 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>;
|
||||
}
|
||||
@ -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 };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user