Typeguards in Typescript
· ☕ 3 min read
Typeguards enable us to process function arguments based on their types.
Consider this example -
1 2 3 4 5 function join(a: string): string { return a; } console.log(join("hello")); // hello What if we want to use join for strings or numbers? We can do a union type like so -