The any type in TypeScript
Sometimes we may need to declare the type of variables that may not be known to us at the time we write the application.
For this, the any
type is used, which allows values to be checked at compile time. Let's look at an example. Let's assign a value of type any
to a variable:
let test: any;
Let's write a number into this variable:
test = 123;
Now let's write the following string into this variable:
test = 'abc';
Without running the code, determine what the result of executing the code will be:
let test1: number = 123;
let test2: string = 'abc';
let test3: any;
test3 = test1;
console.log(test3);
test3 = test2;
console.log(test3);