Skip to content

Commit 88d787c

Browse files
committed
Fix links to constructed enum references
Resolves #2508
1 parent 9999d54 commit 88d787c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- Constructed references to enum types will be properly linked with `@interface`, #2508.
6+
37
## v0.25.9 (2024-02-26)
48

59
### Features

src/lib/converter/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,12 @@ const referenceConverter: TypeConverter<
724724
);
725725
return type;
726726
},
727-
convertType(context, type) {
728-
const symbol = type.aliasSymbol ?? type.getSymbol();
727+
convertType(context, type, node) {
728+
// typeName.symbol handles the case where this is a union which happens to refer
729+
// to an enumeration. TS doesn't put the symbol on the type for some reason, but
730+
// does add it to the constructed type node.
731+
const symbol =
732+
type.aliasSymbol ?? type.getSymbol() ?? node.typeName.symbol;
729733
if (!symbol) {
730734
// This happens when we get a reference to a type parameter
731735
// created within a mapped type, `K` in: `{ [K in T]: string }`

src/test/converter2/issues/gh2508.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export enum Color {
2+
BLUE = "Blue",
3+
RED = "Red",
4+
}
5+
6+
type TypeOf<T> = {
7+
[K in keyof T]: T[K][keyof T[K]];
8+
};
9+
10+
type Foo = {
11+
color: typeof Color;
12+
};
13+
14+
/** @interface */
15+
export type Bar = TypeOf<Foo>;
16+
// ^?

src/test/issues.c2.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,4 +1412,12 @@ describe("Issue Tests", () => {
14121412
// }>(object: I): void
14131413
equal(type?.toString(), "Value & Object");
14141414
});
1415+
1416+
it("Handles constructed references to enumeration types, #2508", () => {
1417+
const project = convert();
1418+
const refl = query(project, "Bar.color");
1419+
equal(refl.type?.type, "reference");
1420+
equal(refl.type.toString(), "Color");
1421+
equal(refl.type.reflection?.id, query(project, "Color").id);
1422+
});
14151423
});

0 commit comments

Comments
 (0)