Course lesson

Prevent Type Widening of Array Literals with TypeScript's const Assertions

A const assertion is a special type assertion that uses the const keyword instead of a specific type name. When using a const assertion on an array literal expression, the resulting type will be a readonly tuple type and no literal types within the expression...

Duration
2 min
Access
Pro
Transcript
Available

A const assertion is a special type assertion that uses the const keyword instead of a specific type name. When using a const assertion on an array literal expression, the resulting type will be a readonly tuple type and no literal types within the expression will be widened.