-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
It seems that when a TypeScript type defines an element with reference to an Enum member, codegen does a straight copy of the definition which leads to an error. See exmaple below:
export enum Ops {
Up = "up",
Down = "down",
Left = "left",
Right = 'right'
}
export interface A {
op: Ops.Down
}
is converted to:
import { Type, Static } from '@sinclair/typebox'
export enum EnumOps {
Up = 'up',
Down = 'down',
Left = 'left',
Right = 'right'
}
export type Ops = Static<typeof Ops>
export const Ops = Type.Enum(EnumOps)
export type A = Static<typeof A>
export const A = Type.Object({
op: Ops.Down
})
This results in an error TypeError: Cannot read properties of undefined (reading '$id')
I believe that the correct output should be op: Type.Literal(EnumOps.Down) instead of op: Ops.Down. This resolves the error.
Metadata
Metadata
Assignees
Labels
No labels