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

Popular posts from this blog

php - Passing multiple values in a url using checkbox -

compilation - PHP install fails on Ubuntu 14 (make: *** [sapi/cli/php] Error 1) PHP 5.6.20 -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -