3

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
Andrew
  • 695
  • 1
  • 8
  • 21
  • 1
    Putting your code into the typescript playground already notifies of the invalid value for order. Are you sure your code is not working as intended? Maybe it's a typescript version issue? – Yoshi Jul 08 '20 at 11:50
  • @Yoshi Yes, looks like it. Thank you – Andrew Jul 08 '20 at 12:21

1 Answers1

2

Your snippet is already working.

Check your typescript configuration and as @Yoshi said, your typescript version.