Reputation: 795
I like to extend my question and ask for a help with interface
example:
const FIRST = "FIRST"
const SECOND = "SECOND"
interface TSomeInterface {
element: Element
order?: typeof FIRST | typeof SECOND // not working, value could be anything
}
How do I restrict the optional order
key to one of the const
above?
To be clear, I want:
{ element: someElement, order: FIRST } // pass
{ element: someElement, order: SECOND } // pass
{ element: someElement, order: "test" } // fail
{ element: someElement, order: "" } // fail
{ element: someElement, order: 0 } // fail
Upvotes: 3
Views: 171
Reputation:
Your snippet is already working.
Check your typescript configuration and as @Yoshi said, your typescript version.
Upvotes: 2