Typescript have concept Union Type to allow assign multiple datatypes/types for single variable.
Syntax :
let myVar: string | number
Use Pipe '|' symbol between two types. Here the variable myVar accepting both string and numbers. Union type is useful for to avoid/reduce the use of any type in our code.
I hope this useful for you. Happy Coding.
0 Comments:
Post a Comment