TypeScript Types

unknown — safely unchecked input

Unknown accepts values of every type but normally requires a narrowing check before member access or assignment to a more specific type. It is useful for inputs whose actual shape has not been established. A typeof check proves only the tested primitive category; validating an object requires checking the relevant members as well. Example output: "5". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.

Formal Syntax & Structure

typescript syntaxtypescript
let value: unknown;

Working Example

Example Snippettypescript
function size(value: unknown): number {  return typeof value === "string" ? value.length : 0;}console.log(size("ready"));
TypeScript Reference