Seeking assistance in understanding how to enforce a specific type for an optional key within an interface:
const FIRST = "FIRST"
const SECOND = "SECOND"
interface TSomeInterface {
element: Element
order?: typeof FIRST | typeof SECOND // not working, value could be anything
}
How can I ensure that the optional order
key is restricted to one of the const
values mentioned above?
To clarify, the desired behavior is as follows:
{ element: someElement, order: FIRST } // pass
{ element: someElement, order: SECOND } // pass
{ element: someElement, order: "test" } // fail
{ element: someElement, order: "" } // fail
{ element: someElement, order: 0 } // fail