diff --git a/testdata/baselines/reference/compiler/callVsFunctionSignature.js b/testdata/baselines/reference/compiler/callVsFunctionSignature.js new file mode 100644 index 0000000000..b36b3cb26e --- /dev/null +++ b/testdata/baselines/reference/compiler/callVsFunctionSignature.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/callVsFunctionSignature.ts] //// + +//// [callVsFunctionSignature.ts] +// Function type parenthesized +type Test1 = T extends (() => infer R) ? R : never; + +// Call signature in type literal +type Test2 = T extends { (): infer R } ? R : never; + +//// [callVsFunctionSignature.js] + + +//// [callVsFunctionSignature.d.ts] +// Function type parenthesized +type Test1 = T extends (() => infer R) ? R : never; +// Call signature in type literal +type Test2 = T extends { + (): infer R; +} ? R : never; diff --git a/testdata/baselines/reference/compiler/callVsFunctionSignature.symbols b/testdata/baselines/reference/compiler/callVsFunctionSignature.symbols new file mode 100644 index 0000000000..4586be3afb --- /dev/null +++ b/testdata/baselines/reference/compiler/callVsFunctionSignature.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/callVsFunctionSignature.ts] //// + +=== callVsFunctionSignature.ts === +// Function type parenthesized +type Test1 = T extends (() => infer R) ? R : never; +>Test1 : Symbol(Test1, Decl(callVsFunctionSignature.ts, 0, 0)) +>T : Symbol(T, Decl(callVsFunctionSignature.ts, 1, 11)) +>T : Symbol(T, Decl(callVsFunctionSignature.ts, 1, 11)) +>R : Symbol(R, Decl(callVsFunctionSignature.ts, 1, 38)) +>R : Symbol(R, Decl(callVsFunctionSignature.ts, 1, 38)) + +// Call signature in type literal +type Test2 = T extends { (): infer R } ? R : never; +>Test2 : Symbol(Test2, Decl(callVsFunctionSignature.ts, 1, 54)) +>T : Symbol(T, Decl(callVsFunctionSignature.ts, 4, 11)) +>T : Symbol(T, Decl(callVsFunctionSignature.ts, 4, 11)) +>R : Symbol(R, Decl(callVsFunctionSignature.ts, 4, 37)) +>R : Symbol(R, Decl(callVsFunctionSignature.ts, 4, 37)) + diff --git a/testdata/baselines/reference/compiler/callVsFunctionSignature.types b/testdata/baselines/reference/compiler/callVsFunctionSignature.types new file mode 100644 index 0000000000..ae9b6221bc --- /dev/null +++ b/testdata/baselines/reference/compiler/callVsFunctionSignature.types @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/callVsFunctionSignature.ts] //// + +=== callVsFunctionSignature.ts === +// Function type parenthesized +type Test1 = T extends (() => infer R) ? R : never; +>Test1 : Test1 + +// Call signature in type literal +type Test2 = T extends { (): infer R } ? R : never; +>Test2 : Test2 + diff --git a/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.js b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.js new file mode 100644 index 0000000000..2d5eee06bb --- /dev/null +++ b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/conditionalTypeWithInferInConstructor.ts] //// + +//// [conditionalTypeWithInferInConstructor.ts] +// This is the exact case from issue #1379 +type ExtractReturn = T extends { new(): infer R } ? R : never; + +//// [conditionalTypeWithInferInConstructor.js] + + +//// [conditionalTypeWithInferInConstructor.d.ts] +// This is the exact case from issue #1379 +type ExtractReturn = T extends { + new (); +} ? R : never; + + +//// [DtsFileErrors] + + +conditionalTypeWithInferInConstructor.d.ts(4,5): error TS2304: Cannot find name 'R'. + + +==== conditionalTypeWithInferInConstructor.d.ts (1 errors) ==== + // This is the exact case from issue #1379 + type ExtractReturn = T extends { + new (); + } ? R : never; + ~ +!!! error TS2304: Cannot find name 'R'. + \ No newline at end of file diff --git a/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.symbols b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.symbols new file mode 100644 index 0000000000..3f4d05464b --- /dev/null +++ b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.symbols @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/conditionalTypeWithInferInConstructor.ts] //// + +=== conditionalTypeWithInferInConstructor.ts === +// This is the exact case from issue #1379 +type ExtractReturn = T extends { new(): infer R } ? R : never; +>ExtractReturn : Symbol(ExtractReturn, Decl(conditionalTypeWithInferInConstructor.ts, 0, 0)) +>T : Symbol(T, Decl(conditionalTypeWithInferInConstructor.ts, 1, 19)) +>T : Symbol(T, Decl(conditionalTypeWithInferInConstructor.ts, 1, 19)) +>R : Symbol(R, Decl(conditionalTypeWithInferInConstructor.ts, 1, 48)) +>R : Symbol(R, Decl(conditionalTypeWithInferInConstructor.ts, 1, 48)) + diff --git a/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.types b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.types new file mode 100644 index 0000000000..960642953b --- /dev/null +++ b/testdata/baselines/reference/compiler/conditionalTypeWithInferInConstructor.types @@ -0,0 +1,7 @@ +//// [tests/cases/compiler/conditionalTypeWithInferInConstructor.ts] //// + +=== conditionalTypeWithInferInConstructor.ts === +// This is the exact case from issue #1379 +type ExtractReturn = T extends { new(): infer R } ? R : never; +>ExtractReturn : ExtractReturn + diff --git a/testdata/tests/cases/compiler/callVsConstructorSig.ts b/testdata/tests/cases/compiler/callVsConstructorSig.ts new file mode 100644 index 0000000000..a7d9dec017 --- /dev/null +++ b/testdata/tests/cases/compiler/callVsConstructorSig.ts @@ -0,0 +1,7 @@ +// @target: esnext +// @module: preserve +// @declaration: true + +// Direct comparison: call signature vs constructor signature +type CallSig = T extends { (): infer R } ? R : never; +type ConstructorSig = T extends { new(): infer R } ? R : never; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/conditionalTypeWithInferInConstructor.ts b/testdata/tests/cases/compiler/conditionalTypeWithInferInConstructor.ts new file mode 100644 index 0000000000..a2a41782a8 --- /dev/null +++ b/testdata/tests/cases/compiler/conditionalTypeWithInferInConstructor.ts @@ -0,0 +1,6 @@ +// @target: esnext +// @module: preserve +// @declaration: true + +// This is the exact case from issue #1379 +type ExtractReturn = T extends { new(): infer R } ? R : never; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/constructorSignatureInfer.ts b/testdata/tests/cases/compiler/constructorSignatureInfer.ts new file mode 100644 index 0000000000..4cfc739055 --- /dev/null +++ b/testdata/tests/cases/compiler/constructorSignatureInfer.ts @@ -0,0 +1,7 @@ +// @declaration: true +// Test case to isolate the constructor signature issue +type ExtractConstructorReturn = T extends { new(): infer R } ? R : never; + +export function test(): ExtractConstructorReturn<{ new(): string }> { + return "" as any; +} \ No newline at end of file diff --git a/testdata/tests/cases/compiler/inferPatternComparison.ts b/testdata/tests/cases/compiler/inferPatternComparison.ts new file mode 100644 index 0000000000..9a9e8a2598 --- /dev/null +++ b/testdata/tests/cases/compiler/inferPatternComparison.ts @@ -0,0 +1,23 @@ +// @target: esnext +// @module: preserve +// @declaration: true + +// Test various patterns to understand where the issue occurs + +// 1. Function parameter (works) +type Test1 = T extends (x: infer R) => any ? R : never; + +// 2. Function return type (should work) +type Test2 = T extends () => infer R ? R : never; + +// 3. Constructor signature return type (broken) +type Test3 = T extends { new(): infer R } ? R : never; + +// 4. Constructor parameter (might be broken too) +type Test4 = T extends { new(x: infer R): any } ? R : never; + +// 5. Call signature return type (should work like function) +type Test5 = T extends { (): infer R } ? R : never; + +// 6. Call signature parameter (should work like function) +type Test6 = T extends { (x: infer R): any } ? R : never; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/sideBySideComparison.ts b/testdata/tests/cases/compiler/sideBySideComparison.ts new file mode 100644 index 0000000000..45813b0347 --- /dev/null +++ b/testdata/tests/cases/compiler/sideBySideComparison.ts @@ -0,0 +1,13 @@ +// @target: esnext +// @module: preserve +// @declaration: true + +// Call signature in type literal - should work +type ExtractCallReturn = T extends { (): infer R } ? R : never; + +// Constructor signature in type literal - should be fixed +type ExtractConstructReturn = T extends { new(): infer R } ? R : never; + +// Test both with same usage +declare const callTest: ExtractCallReturn<() => string>; +declare const constructTest: ExtractConstructReturn<{ new(): string }>; \ No newline at end of file diff --git a/testdata/tests/cases/compiler/simpleInferFunction.ts b/testdata/tests/cases/compiler/simpleInferFunction.ts new file mode 100644 index 0000000000..6c9e9b8372 --- /dev/null +++ b/testdata/tests/cases/compiler/simpleInferFunction.ts @@ -0,0 +1,6 @@ +// @target: esnext +// @module: preserve +// @declaration: true + +// Simple function parameter case +type ExtractParam = T extends (x: infer R) => any ? R : never; \ No newline at end of file