Curriculum
Course: TypeScript
Login
Text lesson

TS Special Types

TypeScript includes special types that don’t necessarily refer to any particular data type.

Type: any

The any type disables type checking and allows any type to be used.

In the example below, any is not used, so an error will be thrown:

Example without any

let u = true;
u = “string”// Error: Type ‘string’ is not assignable to type ‘boolean’.
Math.round(u); // Error: Argument of type ‘boolean’ is not assignable to parameter of type ‘number’.

Assigning a variable the special type any disables type checking.

Example with any

let v: any = true;
v = “string”// no error as it can be “any” type
Math.round(v); // no error as it can be “any” type

Using any can help bypass errors by disabling type checking, but it also means TypeScript won’t provide type safety, and tools like auto-completion will be ineffective. It’s best to avoid using any whenever possible.