Skip to content

Commit

Permalink
feat(compiler): Allow enums and unions in model indexers
Browse files Browse the repository at this point in the history
Signed-off-by: Naoki Ikeguchi <[email protected]>
  • Loading branch information
siketyan committed Jan 12, 2025
1 parent 3ac724c commit 7abf3ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export type NeverIndexer = {
};

export type ModelIndexer = {
readonly key: Scalar;
readonly key: Enum | Scalar | Union;
readonly value: Type;
};

Expand Down
11 changes: 9 additions & 2 deletions packages/compiler/src/lib/intrinsic/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { DocTarget, setDocData } from "../../core/intrinsic-type-state.js";
import type { Program } from "../../core/program.js";
import type { DecoratorContext, ModelIndexer, Scalar, Type } from "../../core/types.js";
import type {
DecoratorContext,
Enum,
ModelIndexer,
Scalar,
Type,
Union,
} from "../../core/types.js";

const indexTypeKey = Symbol.for(`TypeSpec.index`);
export const indexerDecorator = (
context: DecoratorContext,
target: Type,
key: Scalar,
key: Enum | Scalar | Union,
value: Type,
) => {
const indexer: ModelIndexer = { key, value };
Expand Down

0 comments on commit 7abf3ee

Please sign in to comment.