Is there a way to check if a string is included in a Union type in TypeScript? -
consider following code:
type foo = "foo" | "bar" | "baz"  function isinfoo(str: string) boolean {     // return foo.contains(str); ? }   in typescript, there elegant way check if str in type foo?
type foo not compiled generated javascript. can not realized in elegant way. 1 option: use array specified strings, or @ these fields through enum.
Comments
Post a Comment