diff --git a/CHANGELOG.md b/CHANGELOG.md index 36609185a..76020068c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ title: Changelog ## Unreleased +### Bug Fixes + +- Add special handling for import types with type errors discarded with + ts-expect-error, #2792. + ## v0.27.2 (2024-11-29) ### Bug Fixes diff --git a/src/lib/converter/types.ts b/src/lib/converter/types.ts index 72b4ddeef..3b9b91592 100644 --- a/src/lib/converter/types.ts +++ b/src/lib/converter/types.ts @@ -421,7 +421,13 @@ const importType: TypeConverter = { kind: [ts.SyntaxKind.ImportType], convert(context, node) { const name = node.qualifier?.getText() ?? "__module"; - const symbol = context.expectSymbolAtLocation(node.qualifier || node); + const symbol = context.getSymbolAtLocation(node.qualifier || node); + // #2792, we should always have a symbol here unless there is a compiler + // error ignored with ts-expect-error or ts-ignore. + if (!symbol) { + return new IntrinsicType("any"); + } + return ReferenceType.createSymbolReference( context.resolveAliasedSymbol(symbol), context, diff --git a/src/test/converter2/issues/gh2792.ts b/src/test/converter2/issues/gh2792.ts new file mode 100644 index 000000000..cb84e47a0 --- /dev/null +++ b/src/test/converter2/issues/gh2792.ts @@ -0,0 +1,7 @@ +export type TypeNodeType = { + // @ts-expect-error + generated: import("@typedoc/dummy").GeneratedType; +}; + +// @ts-expect-error +export const typeType = null! as import("@typedoc/dummy").GeneratedType; diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index e8f88df22..22ada3863 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -1933,4 +1933,13 @@ describe("Issue Tests", () => { equal(Foo.type?.type, "reference"); equal(Foo.type.reflection?.getFullName(), Bar.getFullName()); }); + + it("#2792 handles @ts-expect-error on import types by converting to any", () => { + const project = convert(); + const node = query(project, "TypeNodeType.generated"); + equal(node.type?.toString(), "any"); + + const type = query(project, "typeType"); + equal(type.type?.toString(), "any"); + }); });