All Our Services

W3Schools offers a wide range of services and products for beginners and professionals, helping millions of people everyday to learn and master new skills.

Type: any

any is a type that disables type checking and effectively allows all types to be used.

The example below does not use any and will throw an error:

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'. Try it Yourself »

Setting any to 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 Try it Yourself »

any can be a useful way to get past errors since it disables type checking, but TypeScript will not be able provide type safety, and tools which rely on type data, such as auto completion, will not work. Remember, it should be avoided at "any" cost...

unknown is a similar, but safer alternative to any .

TypeScript will prevent unknown types from being used, as shown in the below example:

let w: unknown = 1;
w = "string"; // no error
w = {
runANonExistentMethod: () => {
console.log("I think therefore I am");
} as { runANonExistentMethod: () => void}
// How can we avoid the error for the code commented out below when we don't know the type?
// w.runANonExistentMethod(); // Error: Object is of type 'unknown'.
if(typeof w === 'object' && w !== null) {
(w as { runANonExistentMethod: Function }).runANonExistentMethod();
// Although we have to cast multiple times we can do a check in the if to secure our type and have a safer casting Try it Yourself »

Compare the example above to the previous example, with any .

unknown is best used when you don't know the type of data being typed. To add a type later, you'll need to cast it.

Casting is when we use the "as" keyword to say property or variable is of the casted type.

Get Certified!
Complete the TypeScript modules, do the exercises, take the exam and become w3schools certified!!
$45 ENROLL

Type: never

never effectively throws an error whenever it is defined.

let x: never = true; // Error: Type 'boolean' is not assignable to type 'never'. Try it Yourself »

never is rarely used, especially by itself, its primary use is in advanced generics.

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy .

W3Schools is Powered by W3.CSS .