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

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

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

asp.net mvc - breakpoint on javascript in CSHTML? -