Handle composite signatures in isResolvingReturnTypeOfSignature (#55165)

This commit is contained in:
Anders Hejlsberg
2023-07-26 15:22:58 -07:00
committed by GitHub
parent cbf3c63ef3
commit c69f4476af
4 changed files with 99 additions and 2 deletions

View File

@@ -14888,8 +14888,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return getReturnTypeOfTypeTag(declaration);
}
function isResolvingReturnTypeOfSignature(signature: Signature) {
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, TypeSystemPropertyName.ResolvedReturnType) >= 0;
function isResolvingReturnTypeOfSignature(signature: Signature): boolean {
return signature.compositeSignatures && some(signature.compositeSignatures, isResolvingReturnTypeOfSignature) ||
!signature.resolvedReturnType && findResolutionCycleStartIndex(signature, TypeSystemPropertyName.ResolvedReturnType) >= 0;
}
function getRestTypeOfSignature(signature: Signature): Type {

View File

@@ -0,0 +1,33 @@
//// [tests/cases/compiler/compositeContextualSignature.ts] ////
=== compositeContextualSignature.ts ===
// Repro from #55145
function f<T extends any[]>(v: ReadonlyArray<T>) { }
>f : Symbol(f, Decl(compositeContextualSignature.ts, 0, 0))
>T : Symbol(T, Decl(compositeContextualSignature.ts, 2, 11))
>v : Symbol(v, Decl(compositeContextualSignature.ts, 2, 28))
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(compositeContextualSignature.ts, 2, 11))
f([
>f : Symbol(f, Decl(compositeContextualSignature.ts, 0, 0))
[
undefined,
>undefined : Symbol(undefined)
() => { },
],
[
1,
() => {
console.log('Hello')
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
},
],
]);

View File

@@ -0,0 +1,44 @@
//// [tests/cases/compiler/compositeContextualSignature.ts] ////
=== compositeContextualSignature.ts ===
// Repro from #55145
function f<T extends any[]>(v: ReadonlyArray<T>) { }
>f : <T extends any[]>(v: ReadonlyArray<T>) => void
>v : readonly T[]
f([
>f([ [ undefined, () => { }, ], [ 1, () => { console.log('Hello') }, ],]) : void
>f : <T extends any[]>(v: readonly T[]) => void
>[ [ undefined, () => { }, ], [ 1, () => { console.log('Hello') }, ],] : (((() => void) | undefined)[] | (number | (() => void))[])[]
[
>[ undefined, () => { }, ] : ((() => void) | undefined)[]
undefined,
>undefined : undefined
() => { },
>() => { } : () => void
],
[
>[ 1, () => { console.log('Hello') }, ] : (number | (() => void))[]
1,
>1 : 1
() => {
>() => { console.log('Hello') } : () => void
console.log('Hello')
>console.log('Hello') : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>'Hello' : "Hello"
},
],
]);

View File

@@ -0,0 +1,19 @@
// @strict: true
// @noEmit: true
// Repro from #55145
function f<T extends any[]>(v: ReadonlyArray<T>) { }
f([
[
undefined,
() => { },
],
[
1,
() => {
console.log('Hello')
},
],
]);