How to check if a string is included in a certain type

Say you have type Category = "twitter" | "youtube" | "spotify" then you need to check if a string is of type Category what would the condition look like?
1 Reply
Driano
Driano3y ago
Hi @j0hannes . Since TS basically gets removed from your code when you compile, AFAIK there's no way to check just by using the type you defined. You will probably have to check manually (something like ["twitter", "youtube", "spotify"].includes(value)) or use a lib such as Zod.

Did you find this page helpful?