mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 20:44:53 -05:00
Update tests
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
// @strict: true
|
||||
// @declaration: true
|
||||
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
type T02 = Exclude<string | number | (() => void), Function>; // string | number
|
||||
type T03 = Extract<string | number | (() => void), Function>; // () => void
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
@@ -33,23 +29,23 @@ function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
type T10 = Exclude<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
type T11 = Extract<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
type T12 = Exclude<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
type T13 = Extract<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
type T14 = Exclude<Options, { q: "a" }>; // Options
|
||||
type T15 = Extract<Options, { q: "a" }>; // never
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
declare function f4<T extends Options, K extends string>(p: K): Extract<T, { k: K }>;
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
type OptionsOfKind<K extends Options["k"]> = Extract<Options, { k: K }>;
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Extract<T, { [P in K]: V }>;
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ type T04 = Unpacked<Unpacked<Promise<string>[]>>; // string
|
||||
type T05 = Unpacked<any>; // any
|
||||
type T06 = Unpacked<never>; // never
|
||||
|
||||
type ReturnType<T extends Function> = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any;
|
||||
|
||||
function f1(s: string) {
|
||||
return { a: 1, b: s };
|
||||
}
|
||||
@@ -31,11 +29,16 @@ type T11 = ReturnType<(s: string) => void>; // void
|
||||
type T12 = ReturnType<(<T>() => T)>; // {}
|
||||
type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>; // number[]
|
||||
type T14 = ReturnType<typeof f1>; // { a: number, b: string }
|
||||
type T15 = ReturnType<typeof C>; // C
|
||||
type T16 = ReturnType<any>; // any
|
||||
type T17 = ReturnType<never>; // any
|
||||
type T18 = ReturnType<string>; // Error
|
||||
type T19 = ReturnType<Function>; // any
|
||||
type T15 = ReturnType<any>; // any
|
||||
type T16 = ReturnType<never>; // any
|
||||
type T17 = ReturnType<string>; // Error
|
||||
type T18 = ReturnType<Function>; // Error
|
||||
|
||||
type U10 = InstanceType<typeof C>; // C
|
||||
type U11 = InstanceType<any>; // any
|
||||
type U12 = InstanceType<never>; // any
|
||||
type U13 = InstanceType<string>; // Error
|
||||
type U14 = InstanceType<Function>; // Error
|
||||
|
||||
type ArgumentType<T extends (x: any) => any> = T extends (a: infer A) => any ? A : any;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user