TypeScript · Types and shapes

unknown

A safe alternative to any: you must narrow before using the value.

Syntax
value: unknown

Example

Example
function parse(value: unknown) {
  if (typeof value === "string") return value.toUpperCase();
  return "";
}
console.log(parse("ok"));

More in this group

any Array types enums Function type Interface Literal type never null and undefined

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course