From 03a384785fc9c0dc677dc354b0b9c81ce9bd6b85 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 30 Jan 2018 08:11:58 -0800 Subject: [PATCH] Accept new baselines --- .../reference/inferTypes1.errors.txt | 83 +++++ tests/baselines/reference/inferTypes1.js | 183 +++++++++++ tests/baselines/reference/inferTypes1.symbols | 299 +++++++++++++++++ tests/baselines/reference/inferTypes1.types | 303 ++++++++++++++++++ 4 files changed, 868 insertions(+) create mode 100644 tests/baselines/reference/inferTypes1.errors.txt create mode 100644 tests/baselines/reference/inferTypes1.js create mode 100644 tests/baselines/reference/inferTypes1.symbols create mode 100644 tests/baselines/reference/inferTypes1.types diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt new file mode 100644 index 00000000000..0ffcb0a8bd0 --- /dev/null +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -0,0 +1,83 @@ +tests/cases/conformance/types/conditional/inferTypes1.ts(34,23): error TS2344: Type 'string' does not satisfy the constraint 'Function'. +tests/cases/conformance/types/conditional/inferTypes1.ts(43,25): error TS2344: Type '(x: string, y: string) => number' does not satisfy the constraint '(x: any) => any'. +tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'. + Type 'Function' provides no match for the signature '(x: any): any'. + + +==== tests/cases/conformance/types/conditional/inferTypes1.ts (3 errors) ==== + type Unpacked = + T extends (infer U)[] ? U : + T extends (...args: any[]) => infer U ? U : + T extends Promise ? U : + T; + + type T00 = Unpacked; // string + type T01 = Unpacked; // string + type T02 = Unpacked<() => string>; // string + type T03 = Unpacked>; // string + type T04 = Unpacked[]>>; // string + type T05 = Unpacked; // any + type T06 = Unpacked; // never + + type ReturnType = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any; + + function f1(s: string) { + return { a: 1, b: s }; + } + + class C { + x = 0; + y = 0; + } + + type T10 = ReturnType<() => string>; // string + type T11 = ReturnType<(s: string) => void>; // void + type T12 = ReturnType<(() => T)>; // {} + type T13 = ReturnType<(() => T)>; // number[] + type T14 = ReturnType; // { a: number, b: string } + type T15 = ReturnType; // C + type T16 = ReturnType; // any + type T17 = ReturnType; // any + type T18 = ReturnType; // Error + ~~~~~~ +!!! error TS2344: Type 'string' does not satisfy the constraint 'Function'. + type T19 = ReturnType; // any + + type ArgumentType any> = T extends (a: infer A) => any ? A : any; + + type T20 = ArgumentType<() => void>; // never + type T21 = ArgumentType<(x: string) => number>; // string + type T22 = ArgumentType<(x?: string) => number>; // string | undefined + type T23 = ArgumentType<(...args: string[]) => number>; // string + type T24 = ArgumentType<(x: string, y: string) => number>; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2344: Type '(x: string, y: string) => number' does not satisfy the constraint '(x: any) => any'. + type T25 = ArgumentType; // Error + ~~~~~~~~ +!!! error TS2344: Type 'Function' does not satisfy the constraint '(x: any) => any'. +!!! error TS2344: Type 'Function' provides no match for the signature '(x: any): any'. + type T26 = ArgumentType; // any + type T27 = ArgumentType; // any + + type X1 = T extends { x: infer X, y: infer Y } ? [X, Y] : any; + + type T30 = X1<{ x: any, y: any }>; // [any, any] + type T31 = X1<{ x: number, y: string }>; // [number, string] + type T32 = X1<{ x: number, y: string, z: boolean }>; // [number, string] + + type X2 = T extends { a: infer U, b: infer U } ? U : never; + + type T40 = X2<{}>; // never + type T41 = X2<{ a: string }>; // never + type T42 = X2<{ a: string, b: string }>; // string + type T43 = X2<{ a: number, b: string }>; // string | number + type T44 = X2<{ a: number, b: string, c: boolean }>; // string | number + + type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never; + + type T50 = X3<{}>; // never + type T51 = X3<{ a: (x: string) => void }>; // never + type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string + type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number + type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number + \ No newline at end of file diff --git a/tests/baselines/reference/inferTypes1.js b/tests/baselines/reference/inferTypes1.js new file mode 100644 index 00000000000..cfb98ddaf3e --- /dev/null +++ b/tests/baselines/reference/inferTypes1.js @@ -0,0 +1,183 @@ +//// [inferTypes1.ts] +type Unpacked = + T extends (infer U)[] ? U : + T extends (...args: any[]) => infer U ? U : + T extends Promise ? U : + T; + +type T00 = Unpacked; // string +type T01 = Unpacked; // string +type T02 = Unpacked<() => string>; // string +type T03 = Unpacked>; // string +type T04 = Unpacked[]>>; // string +type T05 = Unpacked; // any +type T06 = Unpacked; // never + +type ReturnType = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any; + +function f1(s: string) { + return { a: 1, b: s }; +} + +class C { + x = 0; + y = 0; +} + +type T10 = ReturnType<() => string>; // string +type T11 = ReturnType<(s: string) => void>; // void +type T12 = ReturnType<(() => T)>; // {} +type T13 = ReturnType<(() => T)>; // number[] +type T14 = ReturnType; // { a: number, b: string } +type T15 = ReturnType; // C +type T16 = ReturnType; // any +type T17 = ReturnType; // any +type T18 = ReturnType; // Error +type T19 = ReturnType; // any + +type ArgumentType any> = T extends (a: infer A) => any ? A : any; + +type T20 = ArgumentType<() => void>; // never +type T21 = ArgumentType<(x: string) => number>; // string +type T22 = ArgumentType<(x?: string) => number>; // string | undefined +type T23 = ArgumentType<(...args: string[]) => number>; // string +type T24 = ArgumentType<(x: string, y: string) => number>; // Error +type T25 = ArgumentType; // Error +type T26 = ArgumentType; // any +type T27 = ArgumentType; // any + +type X1 = T extends { x: infer X, y: infer Y } ? [X, Y] : any; + +type T30 = X1<{ x: any, y: any }>; // [any, any] +type T31 = X1<{ x: number, y: string }>; // [number, string] +type T32 = X1<{ x: number, y: string, z: boolean }>; // [number, string] + +type X2 = T extends { a: infer U, b: infer U } ? U : never; + +type T40 = X2<{}>; // never +type T41 = X2<{ a: string }>; // never +type T42 = X2<{ a: string, b: string }>; // string +type T43 = X2<{ a: number, b: string }>; // string | number +type T44 = X2<{ a: number, b: string, c: boolean }>; // string | number + +type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never; + +type T50 = X3<{}>; // never +type T51 = X3<{ a: (x: string) => void }>; // never +type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number + + +//// [inferTypes1.js] +"use strict"; +function f1(s) { + return { a: 1, b: s }; +} +var C = /** @class */ (function () { + function C() { + this.x = 0; + this.y = 0; + } + return C; +}()); + + +//// [inferTypes1.d.ts] +declare type Unpacked = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : T extends Promise ? U : T; +declare type T00 = Unpacked; +declare type T01 = Unpacked; +declare type T02 = Unpacked<() => string>; +declare type T03 = Unpacked>; +declare type T04 = Unpacked[]>>; +declare type T05 = Unpacked; +declare type T06 = Unpacked; +declare type ReturnType = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any; +declare function f1(s: string): { + a: number; + b: string; +}; +declare class C { + x: number; + y: number; +} +declare type T10 = ReturnType<() => string>; +declare type T11 = ReturnType<(s: string) => void>; +declare type T12 = ReturnType<(() => T)>; +declare type T13 = ReturnType<(() => T)>; +declare type T14 = ReturnType; +declare type T15 = ReturnType; +declare type T16 = ReturnType; +declare type T17 = ReturnType; +declare type T18 = ReturnType; +declare type T19 = ReturnType; +declare type ArgumentType any> = T extends (a: infer A) => any ? A : any; +declare type T20 = ArgumentType<() => void>; +declare type T21 = ArgumentType<(x: string) => number>; +declare type T22 = ArgumentType<(x?: string) => number>; +declare type T23 = ArgumentType<(...args: string[]) => number>; +declare type T24 = ArgumentType<(x: string, y: string) => number>; +declare type T25 = ArgumentType; +declare type T26 = ArgumentType; +declare type T27 = ArgumentType; +declare type X1 = T extends { + x: infer X; + y: infer Y; +} ? [X, Y] : any; +declare type T30 = X1<{ + x: any; + y: any; +}>; +declare type T31 = X1<{ + x: number; + y: string; +}>; +declare type T32 = X1<{ + x: number; + y: string; + z: boolean; +}>; +declare type X2 = T extends { + a: infer U; + b: infer U; +} ? U : never; +declare type T40 = X2<{}>; +declare type T41 = X2<{ + a: string; +}>; +declare type T42 = X2<{ + a: string; + b: string; +}>; +declare type T43 = X2<{ + a: number; + b: string; +}>; +declare type T44 = X2<{ + a: number; + b: string; + c: boolean; +}>; +declare type X3 = T extends { + a: (x: infer U) => void; + b: (x: infer U) => void; +} ? U : never; +declare type T50 = X3<{}>; +declare type T51 = X3<{ + a: (x: string) => void; +}>; +declare type T52 = X3<{ + a: (x: string) => void; + b: (x: string) => void; +}>; +declare type T53 = X3<{ + a: (x: number) => void; + b: (x: string) => void; +}>; +declare type T54 = X3<{ + a: (x: number) => void; + b: () => void; +}>; diff --git a/tests/baselines/reference/inferTypes1.symbols b/tests/baselines/reference/inferTypes1.symbols new file mode 100644 index 00000000000..1f9a3de716d --- /dev/null +++ b/tests/baselines/reference/inferTypes1.symbols @@ -0,0 +1,299 @@ +=== tests/cases/conformance/types/conditional/inferTypes1.ts === +type Unpacked = +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(inferTypes1.ts, 0, 14)) + + T extends (infer U)[] ? U : +>T : Symbol(T, Decl(inferTypes1.ts, 0, 14)) +>U : Symbol(U, Decl(inferTypes1.ts, 1, 20)) +>U : Symbol(U, Decl(inferTypes1.ts, 1, 20)) + + T extends (...args: any[]) => infer U ? U : +>T : Symbol(T, Decl(inferTypes1.ts, 0, 14)) +>args : Symbol(args, Decl(inferTypes1.ts, 2, 15)) +>U : Symbol(U, Decl(inferTypes1.ts, 2, 39)) +>U : Symbol(U, Decl(inferTypes1.ts, 2, 39)) + + T extends Promise ? U : +>T : Symbol(T, Decl(inferTypes1.ts, 0, 14)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --)) +>U : Symbol(U, Decl(inferTypes1.ts, 3, 27)) +>U : Symbol(U, Decl(inferTypes1.ts, 3, 27)) + + T; +>T : Symbol(T, Decl(inferTypes1.ts, 0, 14)) + +type T00 = Unpacked; // string +>T00 : Symbol(T00, Decl(inferTypes1.ts, 4, 6)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) + +type T01 = Unpacked; // string +>T01 : Symbol(T01, Decl(inferTypes1.ts, 6, 28)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) + +type T02 = Unpacked<() => string>; // string +>T02 : Symbol(T02, Decl(inferTypes1.ts, 7, 30)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) + +type T03 = Unpacked>; // string +>T03 : Symbol(T03, Decl(inferTypes1.ts, 8, 34)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --)) + +type T04 = Unpacked[]>>; // string +>T04 : Symbol(T04, Decl(inferTypes1.ts, 9, 37)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) +>Promise : Symbol(Promise, Decl(lib.d.ts, --, --)) + +type T05 = Unpacked; // any +>T05 : Symbol(T05, Decl(inferTypes1.ts, 10, 49)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) + +type T06 = Unpacked; // never +>T06 : Symbol(T06, Decl(inferTypes1.ts, 11, 25)) +>Unpacked : Symbol(Unpacked, Decl(inferTypes1.ts, 0, 0)) + +type ReturnType = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any; +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>T : Symbol(T, Decl(inferTypes1.ts, 14, 16)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(inferTypes1.ts, 14, 16)) +>args : Symbol(args, Decl(inferTypes1.ts, 14, 50)) +>R : Symbol(R, Decl(inferTypes1.ts, 14, 74), Decl(inferTypes1.ts, 14, 110)) +>args : Symbol(args, Decl(inferTypes1.ts, 14, 86)) +>R : Symbol(R, Decl(inferTypes1.ts, 14, 74), Decl(inferTypes1.ts, 14, 110)) +>R : Symbol(R, Decl(inferTypes1.ts, 14, 74), Decl(inferTypes1.ts, 14, 110)) + +function f1(s: string) { +>f1 : Symbol(f1, Decl(inferTypes1.ts, 14, 124)) +>s : Symbol(s, Decl(inferTypes1.ts, 16, 12)) + + return { a: 1, b: s }; +>a : Symbol(a, Decl(inferTypes1.ts, 17, 12)) +>b : Symbol(b, Decl(inferTypes1.ts, 17, 18)) +>s : Symbol(s, Decl(inferTypes1.ts, 16, 12)) +} + +class C { +>C : Symbol(C, Decl(inferTypes1.ts, 18, 1)) + + x = 0; +>x : Symbol(C.x, Decl(inferTypes1.ts, 20, 9)) + + y = 0; +>y : Symbol(C.y, Decl(inferTypes1.ts, 21, 10)) +} + +type T10 = ReturnType<() => string>; // string +>T10 : Symbol(T10, Decl(inferTypes1.ts, 23, 1)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) + +type T11 = ReturnType<(s: string) => void>; // void +>T11 : Symbol(T11, Decl(inferTypes1.ts, 25, 36)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>s : Symbol(s, Decl(inferTypes1.ts, 26, 23)) + +type T12 = ReturnType<(() => T)>; // {} +>T12 : Symbol(T12, Decl(inferTypes1.ts, 26, 43)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>T : Symbol(T, Decl(inferTypes1.ts, 27, 24)) +>T : Symbol(T, Decl(inferTypes1.ts, 27, 24)) + +type T13 = ReturnType<(() => T)>; // number[] +>T13 : Symbol(T13, Decl(inferTypes1.ts, 27, 36)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>T : Symbol(T, Decl(inferTypes1.ts, 28, 24)) +>U : Symbol(U, Decl(inferTypes1.ts, 28, 36)) +>U : Symbol(U, Decl(inferTypes1.ts, 28, 36)) +>T : Symbol(T, Decl(inferTypes1.ts, 28, 24)) + +type T14 = ReturnType; // { a: number, b: string } +>T14 : Symbol(T14, Decl(inferTypes1.ts, 28, 66)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>f1 : Symbol(f1, Decl(inferTypes1.ts, 14, 124)) + +type T15 = ReturnType; // C +>T15 : Symbol(T15, Decl(inferTypes1.ts, 29, 33)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>C : Symbol(C, Decl(inferTypes1.ts, 18, 1)) + +type T16 = ReturnType; // any +>T16 : Symbol(T16, Decl(inferTypes1.ts, 30, 32)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) + +type T17 = ReturnType; // any +>T17 : Symbol(T17, Decl(inferTypes1.ts, 31, 27)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) + +type T18 = ReturnType; // Error +>T18 : Symbol(T18, Decl(inferTypes1.ts, 32, 29)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) + +type T19 = ReturnType; // any +>T19 : Symbol(T19, Decl(inferTypes1.ts, 33, 30)) +>ReturnType : Symbol(ReturnType, Decl(inferTypes1.ts, 12, 27)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type ArgumentType any> = T extends (a: infer A) => any ? A : any; +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>T : Symbol(T, Decl(inferTypes1.ts, 36, 18)) +>x : Symbol(x, Decl(inferTypes1.ts, 36, 29)) +>T : Symbol(T, Decl(inferTypes1.ts, 36, 18)) +>a : Symbol(a, Decl(inferTypes1.ts, 36, 58)) +>A : Symbol(A, Decl(inferTypes1.ts, 36, 66)) +>A : Symbol(A, Decl(inferTypes1.ts, 36, 66)) + +type T20 = ArgumentType<() => void>; // never +>T20 : Symbol(T20, Decl(inferTypes1.ts, 36, 87)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) + +type T21 = ArgumentType<(x: string) => number>; // string +>T21 : Symbol(T21, Decl(inferTypes1.ts, 38, 36)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>x : Symbol(x, Decl(inferTypes1.ts, 39, 25)) + +type T22 = ArgumentType<(x?: string) => number>; // string | undefined +>T22 : Symbol(T22, Decl(inferTypes1.ts, 39, 47)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>x : Symbol(x, Decl(inferTypes1.ts, 40, 25)) + +type T23 = ArgumentType<(...args: string[]) => number>; // string +>T23 : Symbol(T23, Decl(inferTypes1.ts, 40, 48)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>args : Symbol(args, Decl(inferTypes1.ts, 41, 25)) + +type T24 = ArgumentType<(x: string, y: string) => number>; // Error +>T24 : Symbol(T24, Decl(inferTypes1.ts, 41, 55)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>x : Symbol(x, Decl(inferTypes1.ts, 42, 25)) +>y : Symbol(y, Decl(inferTypes1.ts, 42, 35)) + +type T25 = ArgumentType; // Error +>T25 : Symbol(T25, Decl(inferTypes1.ts, 42, 58)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + +type T26 = ArgumentType; // any +>T26 : Symbol(T26, Decl(inferTypes1.ts, 43, 34)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) + +type T27 = ArgumentType; // any +>T27 : Symbol(T27, Decl(inferTypes1.ts, 44, 29)) +>ArgumentType : Symbol(ArgumentType, Decl(inferTypes1.ts, 34, 32)) + +type X1 = T extends { x: infer X, y: infer Y } ? [X, Y] : any; +>X1 : Symbol(X1, Decl(inferTypes1.ts, 45, 31)) +>T : Symbol(T, Decl(inferTypes1.ts, 47, 8)) +>x : Symbol(x, Decl(inferTypes1.ts, 47, 19)) +>y : Symbol(y, Decl(inferTypes1.ts, 47, 27)) +>T : Symbol(T, Decl(inferTypes1.ts, 47, 8)) +>x : Symbol(x, Decl(inferTypes1.ts, 47, 51)) +>X : Symbol(X, Decl(inferTypes1.ts, 47, 60)) +>y : Symbol(y, Decl(inferTypes1.ts, 47, 63)) +>Y : Symbol(Y, Decl(inferTypes1.ts, 47, 72)) +>X : Symbol(X, Decl(inferTypes1.ts, 47, 60)) +>Y : Symbol(Y, Decl(inferTypes1.ts, 47, 72)) + +type T30 = X1<{ x: any, y: any }>; // [any, any] +>T30 : Symbol(T30, Decl(inferTypes1.ts, 47, 92)) +>X1 : Symbol(X1, Decl(inferTypes1.ts, 45, 31)) +>x : Symbol(x, Decl(inferTypes1.ts, 49, 15)) +>y : Symbol(y, Decl(inferTypes1.ts, 49, 23)) + +type T31 = X1<{ x: number, y: string }>; // [number, string] +>T31 : Symbol(T31, Decl(inferTypes1.ts, 49, 34)) +>X1 : Symbol(X1, Decl(inferTypes1.ts, 45, 31)) +>x : Symbol(x, Decl(inferTypes1.ts, 50, 15)) +>y : Symbol(y, Decl(inferTypes1.ts, 50, 26)) + +type T32 = X1<{ x: number, y: string, z: boolean }>; // [number, string] +>T32 : Symbol(T32, Decl(inferTypes1.ts, 50, 40)) +>X1 : Symbol(X1, Decl(inferTypes1.ts, 45, 31)) +>x : Symbol(x, Decl(inferTypes1.ts, 51, 15)) +>y : Symbol(y, Decl(inferTypes1.ts, 51, 26)) +>z : Symbol(z, Decl(inferTypes1.ts, 51, 37)) + +type X2 = T extends { a: infer U, b: infer U } ? U : never; +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) +>T : Symbol(T, Decl(inferTypes1.ts, 53, 8)) +>T : Symbol(T, Decl(inferTypes1.ts, 53, 8)) +>a : Symbol(a, Decl(inferTypes1.ts, 53, 24)) +>U : Symbol(U, Decl(inferTypes1.ts, 53, 33), Decl(inferTypes1.ts, 53, 45)) +>b : Symbol(b, Decl(inferTypes1.ts, 53, 36)) +>U : Symbol(U, Decl(inferTypes1.ts, 53, 33), Decl(inferTypes1.ts, 53, 45)) +>U : Symbol(U, Decl(inferTypes1.ts, 53, 33), Decl(inferTypes1.ts, 53, 45)) + +type T40 = X2<{}>; // never +>T40 : Symbol(T40, Decl(inferTypes1.ts, 53, 62)) +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) + +type T41 = X2<{ a: string }>; // never +>T41 : Symbol(T41, Decl(inferTypes1.ts, 55, 18)) +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 56, 15)) + +type T42 = X2<{ a: string, b: string }>; // string +>T42 : Symbol(T42, Decl(inferTypes1.ts, 56, 29)) +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 57, 15)) +>b : Symbol(b, Decl(inferTypes1.ts, 57, 26)) + +type T43 = X2<{ a: number, b: string }>; // string | number +>T43 : Symbol(T43, Decl(inferTypes1.ts, 57, 40)) +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 58, 15)) +>b : Symbol(b, Decl(inferTypes1.ts, 58, 26)) + +type T44 = X2<{ a: number, b: string, c: boolean }>; // string | number +>T44 : Symbol(T44, Decl(inferTypes1.ts, 58, 40)) +>X2 : Symbol(X2, Decl(inferTypes1.ts, 51, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 59, 15)) +>b : Symbol(b, Decl(inferTypes1.ts, 59, 26)) +>c : Symbol(c, Decl(inferTypes1.ts, 59, 37)) + +type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never; +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) +>T : Symbol(T, Decl(inferTypes1.ts, 61, 8)) +>T : Symbol(T, Decl(inferTypes1.ts, 61, 8)) +>a : Symbol(a, Decl(inferTypes1.ts, 61, 24)) +>x : Symbol(x, Decl(inferTypes1.ts, 61, 29)) +>U : Symbol(U, Decl(inferTypes1.ts, 61, 37), Decl(inferTypes1.ts, 61, 62)) +>b : Symbol(b, Decl(inferTypes1.ts, 61, 49)) +>x : Symbol(x, Decl(inferTypes1.ts, 61, 54)) +>U : Symbol(U, Decl(inferTypes1.ts, 61, 37), Decl(inferTypes1.ts, 61, 62)) +>U : Symbol(U, Decl(inferTypes1.ts, 61, 37), Decl(inferTypes1.ts, 61, 62)) + +type T50 = X3<{}>; // never +>T50 : Symbol(T50, Decl(inferTypes1.ts, 61, 88)) +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) + +type T51 = X3<{ a: (x: string) => void }>; // never +>T51 : Symbol(T51, Decl(inferTypes1.ts, 63, 18)) +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 64, 15)) +>x : Symbol(x, Decl(inferTypes1.ts, 64, 20)) + +type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string +>T52 : Symbol(T52, Decl(inferTypes1.ts, 64, 42)) +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 65, 15)) +>x : Symbol(x, Decl(inferTypes1.ts, 65, 20)) +>b : Symbol(b, Decl(inferTypes1.ts, 65, 39)) +>x : Symbol(x, Decl(inferTypes1.ts, 65, 44)) + +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +>T53 : Symbol(T53, Decl(inferTypes1.ts, 65, 66)) +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 66, 15)) +>x : Symbol(x, Decl(inferTypes1.ts, 66, 20)) +>b : Symbol(b, Decl(inferTypes1.ts, 66, 39)) +>x : Symbol(x, Decl(inferTypes1.ts, 66, 44)) + +type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number +>T54 : Symbol(T54, Decl(inferTypes1.ts, 66, 66)) +>X3 : Symbol(X3, Decl(inferTypes1.ts, 59, 52)) +>a : Symbol(a, Decl(inferTypes1.ts, 67, 15)) +>x : Symbol(x, Decl(inferTypes1.ts, 67, 20)) +>b : Symbol(b, Decl(inferTypes1.ts, 67, 39)) + diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types new file mode 100644 index 00000000000..dc926c1f496 --- /dev/null +++ b/tests/baselines/reference/inferTypes1.types @@ -0,0 +1,303 @@ +=== tests/cases/conformance/types/conditional/inferTypes1.ts === +type Unpacked = +>Unpacked : Unpacked +>T : T + + T extends (infer U)[] ? U : +>T : T +>U : U +>U : U + + T extends (...args: any[]) => infer U ? U : +>T : T +>args : any[] +>U : U +>U : U + + T extends Promise ? U : +>T : T +>Promise : Promise +>U : U +>U : U + + T; +>T : T + +type T00 = Unpacked; // string +>T00 : string +>Unpacked : Unpacked + +type T01 = Unpacked; // string +>T01 : string +>Unpacked : Unpacked + +type T02 = Unpacked<() => string>; // string +>T02 : string +>Unpacked : Unpacked + +type T03 = Unpacked>; // string +>T03 : string +>Unpacked : Unpacked +>Promise : Promise + +type T04 = Unpacked[]>>; // string +>T04 : string +>Unpacked : Unpacked +>Unpacked : Unpacked +>Promise : Promise + +type T05 = Unpacked; // any +>T05 : any +>Unpacked : Unpacked + +type T06 = Unpacked; // never +>T06 : never +>Unpacked : Unpacked + +type ReturnType = T extends ((...args: any[]) => infer R) | (new (...args: any[]) => infer R) ? R : any; +>ReturnType : ReturnType +>T : T +>Function : Function +>T : T +>args : any[] +>R : R +>args : any[] +>R : R +>R : R + +function f1(s: string) { +>f1 : (s: string) => { a: number; b: string; } +>s : string + + return { a: 1, b: s }; +>{ a: 1, b: s } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>s : string +} + +class C { +>C : C + + x = 0; +>x : number +>0 : 0 + + y = 0; +>y : number +>0 : 0 +} + +type T10 = ReturnType<() => string>; // string +>T10 : string +>ReturnType : ReturnType + +type T11 = ReturnType<(s: string) => void>; // void +>T11 : void +>ReturnType : ReturnType +>s : string + +type T12 = ReturnType<(() => T)>; // {} +>T12 : {} +>ReturnType : ReturnType +>T : T +>T : T + +type T13 = ReturnType<(() => T)>; // number[] +>T13 : number[] +>ReturnType : ReturnType +>T : T +>U : U +>U : U +>T : T + +type T14 = ReturnType; // { a: number, b: string } +>T14 : { a: number; b: string; } +>ReturnType : ReturnType +>f1 : (s: string) => { a: number; b: string; } + +type T15 = ReturnType; // C +>T15 : C +>ReturnType : ReturnType +>C : typeof C + +type T16 = ReturnType; // any +>T16 : any +>ReturnType : ReturnType + +type T17 = ReturnType; // any +>T17 : any +>ReturnType : ReturnType + +type T18 = ReturnType; // Error +>T18 : any +>ReturnType : ReturnType + +type T19 = ReturnType; // any +>T19 : any +>ReturnType : ReturnType +>Function : Function + +type ArgumentType any> = T extends (a: infer A) => any ? A : any; +>ArgumentType : ArgumentType +>T : T +>x : any +>T : T +>a : A +>A : A +>A : A + +type T20 = ArgumentType<() => void>; // never +>T20 : never +>ArgumentType : ArgumentType + +type T21 = ArgumentType<(x: string) => number>; // string +>T21 : string +>ArgumentType : ArgumentType +>x : string + +type T22 = ArgumentType<(x?: string) => number>; // string | undefined +>T22 : string | undefined +>ArgumentType : ArgumentType +>x : string | undefined + +type T23 = ArgumentType<(...args: string[]) => number>; // string +>T23 : string +>ArgumentType : ArgumentType +>args : string[] + +type T24 = ArgumentType<(x: string, y: string) => number>; // Error +>T24 : any +>ArgumentType : ArgumentType +>x : string +>y : string + +type T25 = ArgumentType; // Error +>T25 : any +>ArgumentType : ArgumentType +>Function : Function + +type T26 = ArgumentType; // any +>T26 : any +>ArgumentType : ArgumentType + +type T27 = ArgumentType; // any +>T27 : any +>ArgumentType : ArgumentType + +type X1 = T extends { x: infer X, y: infer Y } ? [X, Y] : any; +>X1 : X1 +>T : T +>x : any +>y : any +>T : T +>x : X +>X : X +>y : Y +>Y : Y +>X : X +>Y : Y + +type T30 = X1<{ x: any, y: any }>; // [any, any] +>T30 : [any, any] +>X1 : X1 +>x : any +>y : any + +type T31 = X1<{ x: number, y: string }>; // [number, string] +>T31 : [number, string] +>X1 : X1 +>x : number +>y : string + +type T32 = X1<{ x: number, y: string, z: boolean }>; // [number, string] +>T32 : [number, string] +>X1 : X1 +>x : number +>y : string +>z : boolean + +type X2 = T extends { a: infer U, b: infer U } ? U : never; +>X2 : X2 +>T : T +>T : T +>a : U +>U : U +>b : U +>U : U +>U : U + +type T40 = X2<{}>; // never +>T40 : never +>X2 : X2 + +type T41 = X2<{ a: string }>; // never +>T41 : never +>X2 : X2 +>a : string + +type T42 = X2<{ a: string, b: string }>; // string +>T42 : string +>X2 : X2 +>a : string +>b : string + +type T43 = X2<{ a: number, b: string }>; // string | number +>T43 : string | number +>X2 : X2 +>a : number +>b : string + +type T44 = X2<{ a: number, b: string, c: boolean }>; // string | number +>T44 : string | number +>X2 : X2 +>a : number +>b : string +>c : boolean + +type X3 = T extends { a: (x: infer U) => void, b: (x: infer U) => void } ? U : never; +>X3 : X3 +>T : T +>T : T +>a : (x: U) => void +>x : U +>U : U +>b : (x: U) => void +>x : U +>U : U +>U : U + +type T50 = X3<{}>; // never +>T50 : never +>X3 : X3 + +type T51 = X3<{ a: (x: string) => void }>; // never +>T51 : never +>X3 : X3 +>a : (x: string) => void +>x : string + +type T52 = X3<{ a: (x: string) => void, b: (x: string) => void }>; // string +>T52 : string +>X3 : X3 +>a : (x: string) => void +>x : string +>b : (x: string) => void +>x : string + +type T53 = X3<{ a: (x: number) => void, b: (x: string) => void }>; // string & number +>T53 : number & string +>X3 : X3 +>a : (x: number) => void +>x : number +>b : (x: string) => void +>x : string + +type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number +>T54 : number +>X3 : X3 +>a : (x: number) => void +>x : number +>b : () => void +