Open In App

Difference between Unknown & Any Type in TypeScript

Last Updated : 23 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The unknown and any type can be used to represent the value of any kind of data type available in TypeScript. The below table lists the differences between them:

unknown

any

The variables with unknown type can store the values of any type with strict type checking.

The any type also allows the variables to store values of any type but causes type-checking errors.

It offers type inference with refined type checking.

It does not offer the type inference.

Type checking is enforced more strictly on these variables.

Type checks can not be enforced on any type variable.

Variables with unknown type are not compatible with all other types.

any type variables are compatible with all other types available in TypeScript.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads