Fix crash in recursive declared type resolution (#23950)

When one type has a type parameter with a default
This commit is contained in:
Nathan Shively-Sanders 2018-05-09 09:25:00 -07:00 committed by GitHub
parent b31968a598
commit e27fb0651b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 1 deletions

View File

@ -5656,6 +5656,10 @@ namespace ts {
const symbol = type.symbol;
const members = getMembersOfSymbol(symbol);
(<InterfaceTypeWithDeclaredMembers>type).declaredProperties = getNamedMembers(members);
// Start with signatures at empty array in case of recursive types
(<InterfaceTypeWithDeclaredMembers>type).declaredCallSignatures = emptyArray;
(<InterfaceTypeWithDeclaredMembers>type).declaredConstructSignatures = emptyArray;
(<InterfaceTypeWithDeclaredMembers>type).declaredCallSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.Call));
(<InterfaceTypeWithDeclaredMembers>type).declaredConstructSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.New));
(<InterfaceTypeWithDeclaredMembers>type).declaredStringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String);
@ -7048,7 +7052,7 @@ namespace ts {
for (let i = numTypeArguments; i < numTypeParameters; i++) {
const mapper = createTypeMapper(typeParameters, typeArguments);
let defaultType = getDefaultFromTypeParameter(typeParameters[i]);
if (defaultType && isTypeIdenticalTo(defaultType, emptyObjectType) && isJavaScriptImplicitAny) {
if (isJavaScriptImplicitAny && defaultType && isTypeIdenticalTo(defaultType, emptyObjectType)) {
defaultType = anyType;
}
typeArguments[i] = defaultType ? instantiateType(defaultType, mapper) : getDefaultTypeArgumentType(isJavaScriptImplicitAny);

View File

@ -0,0 +1,18 @@
=== tests/cases/compiler/types.ts ===
// #23025
export interface F {
>F : Symbol(F, Decl(types.ts, 0, 0))
(): E;
>E : Symbol(E, Decl(other.js, 0, 4))
}
export interface D<T extends F = F> {}
>D : Symbol(D, Decl(types.ts, 3, 1))
>T : Symbol(T, Decl(types.ts, 4, 19))
>F : Symbol(F, Decl(types.ts, 0, 0))
>F : Symbol(F, Decl(types.ts, 0, 0))
=== tests/cases/compiler/other.js ===
/** @typedef {import("./types").D} E */
No type information for this code.
No type information for this code.

View File

@ -0,0 +1,18 @@
=== tests/cases/compiler/types.ts ===
// #23025
export interface F {
>F : F
(): E;
>E : D<any>
}
export interface D<T extends F = F> {}
>D : D<T>
>T : T
>F : F
>F : F
=== tests/cases/compiler/other.js ===
/** @typedef {import("./types").D} E */
No type information for this code.
No type information for this code.

View File

@ -0,0 +1,12 @@
// #23025
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: types.ts
export interface F {
(): E;
}
export interface D<T extends F = F> {}
// @Filename: other.js
/** @typedef {import("./types").D} E */