Skip to content

Commit

Permalink
Add handling for ts-expect-error on import types
Browse files Browse the repository at this point in the history
See #2792
  • Loading branch information
Gerrit0 committed Nov 30, 2024
1 parent 23e2c99 commit 25e59ff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,13 @@ const importType: TypeConverter<ts.ImportTypeNode> = {
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,
Expand Down
7 changes: 7 additions & 0 deletions src/test/converter2/issues/gh2792.ts
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit 25e59ff

Please sign in to comment.