- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 103字
- 2021-07-15 17:05:30
Any
The any data type is a dynamic data type that can hold any value. TypeScript throws compile time errors if you assign a string variable to an integer variable. If you are not sure about what value a variable is going to hold and you would like to opt out of compiler-checking for the type in the assignment, you can use the any data type:
var mixedList:any[] = [1, "I am string", false]; mixedList [2] = "no you are not";
Here, we used an array of the any type so that it can hold any type, such as numbers, strings, and booleans.