Type Assertions
as tells the compiler to treat a value as another type. It does not convert anything at runtime. satisfies checks a value against a type but keeps the precise inferred type.
Example
const input = "42" as unknown as string;
const el = { id: 1 } as { id: number };
const palette = { red: [255, 0, 0], green: "#0f0" } satisfies Record<string, string | number[]>;
console.log(palette.red.length, input.length, el.id);Result
3 2 1
Exercise
Assert a type.
value string
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.