Skip to content

Commit

Permalink
Fix links to constructed enum references
Browse files Browse the repository at this point in the history
Resolves #2508
  • Loading branch information
Gerrit0 committed Mar 3, 2024
1 parent 9999d54 commit 88d787c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Constructed references to enum types will be properly linked with `@interface`, #2508.

## v0.25.9 (2024-02-26)

### Features
Expand Down
8 changes: 6 additions & 2 deletions src/lib/converter/types.ts
Expand Up @@ -724,8 +724,12 @@ const referenceConverter: TypeConverter<
);
return type;
},
convertType(context, type) {
const symbol = type.aliasSymbol ?? type.getSymbol();
convertType(context, type, node) {
// typeName.symbol handles the case where this is a union which happens to refer
// to an enumeration. TS doesn't put the symbol on the type for some reason, but
// does add it to the constructed type node.
const symbol =
type.aliasSymbol ?? type.getSymbol() ?? node.typeName.symbol;
if (!symbol) {
// This happens when we get a reference to a type parameter
// created within a mapped type, `K` in: `{ [K in T]: string }`
Expand Down
16 changes: 16 additions & 0 deletions src/test/converter2/issues/gh2508.ts
@@ -0,0 +1,16 @@
export enum Color {
BLUE = "Blue",
RED = "Red",
}

type TypeOf<T> = {
[K in keyof T]: T[K][keyof T[K]];
};

type Foo = {
color: typeof Color;
};

/** @interface */
export type Bar = TypeOf<Foo>;
// ^?
8 changes: 8 additions & 0 deletions src/test/issues.c2.test.ts
Expand Up @@ -1412,4 +1412,12 @@ describe("Issue Tests", () => {
// }>(object: I): void
equal(type?.toString(), "Value & Object");
});

it("Handles constructed references to enumeration types, #2508", () => {
const project = convert();
const refl = query(project, "Bar.color");
equal(refl.type?.type, "reference");
equal(refl.type.toString(), "Color");
equal(refl.type.reflection?.id, query(project, "Color").id);
});
});

0 comments on commit 88d787c

Please sign in to comment.