Explicitly type strings, numbers, and booleans.
Section: Primitive Types and Annotations
Annotate basic variables
typescript
typescript
const appName: string = "CheatSheet";
const port: number = 3000;
const isProd: boolean = false;Explanation
Type annotations are optional in many cases because TypeScript can infer them.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Primitive Types and Annotations
Annotate object shapes
Describe the expected properties of an object.
Restrict values with literal unions
Use exact string values for safer APIs.
Freeze literals with `as const`
Preserve readonly literal values for objects and arrays.