Skip to content

Commit 25e59ff

Browse files
committed
Add handling for ts-expect-error on import types
See #2792
1 parent 23e2c99 commit 25e59ff

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ title: Changelog
44

55
## Unreleased
66

7+
### Bug Fixes
8+
9+
- Add special handling for import types with type errors discarded with
10+
ts-expect-error, #2792.
11+
712
## v0.27.2 (2024-11-29)
813

914
### Bug Fixes

src/lib/converter/types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,13 @@ const importType: TypeConverter<ts.ImportTypeNode> = {
421421
kind: [ts.SyntaxKind.ImportType],
422422
convert(context, node) {
423423
const name = node.qualifier?.getText() ?? "__module";
424-
const symbol = context.expectSymbolAtLocation(node.qualifier || node);
424+
const symbol = context.getSymbolAtLocation(node.qualifier || node);
425+
// #2792, we should always have a symbol here unless there is a compiler
426+
// error ignored with ts-expect-error or ts-ignore.
427+
if (!symbol) {
428+
return new IntrinsicType("any");
429+
}
430+
425431
return ReferenceType.createSymbolReference(
426432
context.resolveAliasedSymbol(symbol),
427433
context,

src/test/converter2/issues/gh2792.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type TypeNodeType = {
2+
// @ts-expect-error
3+
generated: import("@typedoc/dummy").GeneratedType;
4+
};
5+
6+
// @ts-expect-error
7+
export const typeType = null! as import("@typedoc/dummy").GeneratedType;

src/test/issues.c2.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1933,4 +1933,13 @@ describe("Issue Tests", () => {
19331933
equal(Foo.type?.type, "reference");
19341934
equal(Foo.type.reflection?.getFullName(), Bar.getFullName());
19351935
});
1936+
1937+
it("#2792 handles @ts-expect-error on import types by converting to any", () => {
1938+
const project = convert();
1939+
const node = query(project, "TypeNodeType.generated");
1940+
equal(node.type?.toString(), "any");
1941+
1942+
const type = query(project, "typeType");
1943+
equal(type.type?.toString(), "any");
1944+
});
19361945
});

0 commit comments

Comments
 (0)