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:
Sheetal Nandi
2016-10-06 13:18:41 -07:00
committed by GitHub
5 changed files with 38 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -0,0 +1,6 @@
//// [selfReference.ts]
declare function asFunction<T>(value: T): () => T;
asFunction(() => { return 1; });
//// [selfReference.js]
asFunction(function () { return 1; });

View 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))

View 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

View File

@@ -0,0 +1,3 @@
// @noImplicitAny: true
declare function asFunction<T>(value: T): () => T;
asFunction(() => { return 1; });