mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-04 14:08:20 -06:00
Fix crash in recursive declared type resolution (#23950)
When one type has a type parameter with a default
This commit is contained in:
parent
b31968a598
commit
e27fb0651b
@ -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);
|
||||
|
||||
@ -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.
|
||||
@ -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.
|
||||
12
tests/cases/compiler/recursiveResolveDeclaredMembers.ts
Normal file
12
tests/cases/compiler/recursiveResolveDeclaredMembers.ts
Normal 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 */
|
||||
Loading…
x
Reference in New Issue
Block a user