object literal
An object written out in code with curly braces, such as { id: "usr_100", email: "alex@example.com" }.
In more detail
TypeScript infers a type from an object literal's properties. Object literals written directly where a type is expected get excess property checking. Adding as const makes all its properties readonly literal types.
Related terms
- excess property checking — An extra TypeScript check that rejects unknown properties when an object literal is written directly where a type is expected.
- as const — The TypeScript suffix as const, which tells the compiler to treat an object's values as fixed literal values rather than general types.
- type inference — The compiler working out a type from the code itself, so you do not have to write it out by hand.
Taught in
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript