mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #11427 from Microsoft/implictAnySelfRef
Do not get return type from contextual signature if we are already in process of getting return type of it
This commit is contained in:
@@ -12771,7 +12771,10 @@ namespace ts {
|
||||
if (!contextualSignature) {
|
||||
reportErrorsFromWidening(func, type);
|
||||
}
|
||||
if (isUnitType(type) && !(contextualSignature && isLiteralContextualType(getReturnTypeOfSignature(contextualSignature)))) {
|
||||
if (isUnitType(type) &&
|
||||
!(contextualSignature &&
|
||||
isLiteralContextualType(
|
||||
contextualSignature === getSignatureFromDeclaration(func) ? type : getReturnTypeOfSignature(contextualSignature)))) {
|
||||
type = getWidenedLiteralType(type);
|
||||
}
|
||||
|
||||
|
||||
6
tests/baselines/reference/selfReference.js
Normal file
6
tests/baselines/reference/selfReference.js
Normal file
@@ -0,0 +1,6 @@
|
||||
//// [selfReference.ts]
|
||||
declare function asFunction<T>(value: T): () => T;
|
||||
asFunction(() => { return 1; });
|
||||
|
||||
//// [selfReference.js]
|
||||
asFunction(function () { return 1; });
|
||||
11
tests/baselines/reference/selfReference.symbols
Normal file
11
tests/baselines/reference/selfReference.symbols
Normal file
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/selfReference.ts ===
|
||||
declare function asFunction<T>(value: T): () => T;
|
||||
>asFunction : Symbol(asFunction, Decl(selfReference.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(selfReference.ts, 0, 28))
|
||||
>value : Symbol(value, Decl(selfReference.ts, 0, 31))
|
||||
>T : Symbol(T, Decl(selfReference.ts, 0, 28))
|
||||
>T : Symbol(T, Decl(selfReference.ts, 0, 28))
|
||||
|
||||
asFunction(() => { return 1; });
|
||||
>asFunction : Symbol(asFunction, Decl(selfReference.ts, 0, 0))
|
||||
|
||||
14
tests/baselines/reference/selfReference.types
Normal file
14
tests/baselines/reference/selfReference.types
Normal file
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/selfReference.ts ===
|
||||
declare function asFunction<T>(value: T): () => T;
|
||||
>asFunction : <T>(value: T) => () => T
|
||||
>T : T
|
||||
>value : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
asFunction(() => { return 1; });
|
||||
>asFunction(() => { return 1; }) : () => () => 1
|
||||
>asFunction : <T>(value: T) => () => T
|
||||
>() => { return 1; } : () => 1
|
||||
>1 : 1
|
||||
|
||||
3
tests/cases/compiler/selfReference.ts
Normal file
3
tests/cases/compiler/selfReference.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// @noImplicitAny: true
|
||||
declare function asFunction<T>(value: T): () => T;
|
||||
asFunction(() => { return 1; });
|
||||
Reference in New Issue
Block a user