diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt index 0ffcb0a8bd0..79a0e430cbd 100644 --- a/tests/baselines/reference/inferTypes1.errors.txt +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -2,9 +2,17 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(34,23): error TS2344: T 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(70,12): error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. +tests/cases/conformance/types/conditional/inferTypes1.ts(71,15): error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. +tests/cases/conformance/types/conditional/inferTypes1.ts(71,41): error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. +tests/cases/conformance/types/conditional/inferTypes1.ts(71,51): error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. +tests/cases/conformance/types/conditional/inferTypes1.ts(72,15): error TS2304: Cannot find name 'U'. +tests/cases/conformance/types/conditional/inferTypes1.ts(72,15): error TS4081: Exported type alias 'T62' has or is using private name 'U'. +tests/cases/conformance/types/conditional/inferTypes1.ts(72,43): error TS2304: Cannot find name 'U'. +tests/cases/conformance/types/conditional/inferTypes1.ts(72,43): error TS4081: Exported type alias 'T62' has or is using private name 'U'. -==== tests/cases/conformance/types/conditional/inferTypes1.ts (3 errors) ==== +==== tests/cases/conformance/types/conditional/inferTypes1.ts (11 errors) ==== type Unpacked = T extends (infer U)[] ? U : T extends (...args: any[]) => infer U ? U : @@ -80,4 +88,24 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(44,25): error TS2344: T 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 + + type T60 = infer U; // Error + ~~~~~~~ +!!! error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. + type T61 = infer A extends infer B ? infer C : infer D; // Error + ~~~~~~~ +!!! error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. + ~~~~~~~ +!!! error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. + ~~~~~~~ +!!! error TS1338: 'infer' declarations are only permitted in the 'extends' clause of a conditional type. + type T62 = U extends (infer U)[] ? U : U; // Error + ~ +!!! error TS2304: Cannot find name 'U'. + ~ +!!! error TS4081: Exported type alias 'T62' has or is using private name 'U'. + ~ +!!! error TS2304: Cannot find name 'U'. + ~ +!!! error TS4081: Exported type alias 'T62' has or is using private name 'U'. \ No newline at end of file diff --git a/tests/baselines/reference/inferTypes1.js b/tests/baselines/reference/inferTypes1.js index cfb98ddaf3e..231c39e8952 100644 --- a/tests/baselines/reference/inferTypes1.js +++ b/tests/baselines/reference/inferTypes1.js @@ -67,6 +67,10 @@ 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 + +type T60 = infer U; // Error +type T61 = infer A extends infer B ? infer C : infer D; // Error +type T62 = U extends (infer U)[] ? U : U; // Error //// [inferTypes1.js] @@ -81,103 +85,3 @@ var C = /** @class */ (function () { } 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 index 1f9a3de716d..a85f124dede 100644 --- a/tests/baselines/reference/inferTypes1.symbols +++ b/tests/baselines/reference/inferTypes1.symbols @@ -297,3 +297,21 @@ type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number >x : Symbol(x, Decl(inferTypes1.ts, 67, 20)) >b : Symbol(b, Decl(inferTypes1.ts, 67, 39)) +type T60 = infer U; // Error +>T60 : Symbol(T60, Decl(inferTypes1.ts, 67, 57)) +>U : Symbol(U, Decl(inferTypes1.ts, 69, 16)) + +type T61 = infer A extends infer B ? infer C : infer D; // Error +>T61 : Symbol(T61, Decl(inferTypes1.ts, 69, 19)) +>T : Symbol(T, Decl(inferTypes1.ts, 70, 9)) +>A : Symbol(A, Decl(inferTypes1.ts, 70, 19)) +>B : Symbol(B, Decl(inferTypes1.ts, 70, 35)) +>C : Symbol(C, Decl(inferTypes1.ts, 70, 45)) +>D : Symbol(D, Decl(inferTypes1.ts, 70, 55)) + +type T62 = U extends (infer U)[] ? U : U; // Error +>T62 : Symbol(T62, Decl(inferTypes1.ts, 70, 58)) +>T : Symbol(T, Decl(inferTypes1.ts, 71, 9)) +>U : Symbol(U, Decl(inferTypes1.ts, 71, 30)) +>U : Symbol(U, Decl(inferTypes1.ts, 71, 30)) + diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types index dc926c1f496..be974f8661a 100644 --- a/tests/baselines/reference/inferTypes1.types +++ b/tests/baselines/reference/inferTypes1.types @@ -301,3 +301,23 @@ type T54 = X3<{ a: (x: number) => void, b: () => void }>; // number >x : number >b : () => void +type T60 = infer U; // Error +>T60 : U +>U : U + +type T61 = infer A extends infer B ? infer C : infer D; // Error +>T61 : never +>T : T +>A : A +>B : B +>C : C +>D : D + +type T62 = U extends (infer U)[] ? U : U; // Error +>T62 : any +>T : T +>U : No type information available! +>U : U +>U : U +>U : No type information available! +