Welcome to TS_Handson!
This repository provides practical TypeScript examples focused on simple types and their real-world usage. All examples are located in the TypeScript_SimpleTypes directory.
TS_Handson/
│
├── TypeScript_SimpleTypes/
│ ├── TypeAssignment.ts
│ ├── TypeScriptArrays.ts
│ ├── TypeScriptObjectTypes.ts
│ ├── TypeScriptSpecialTypes.ts
│ └── TypeScriptTuples.ts
└── README.md
- Purpose: Demonstrates how to assign values to variables using TypeScript's basic types.
- Topics Covered:
- Explicit and implicit typing
- Assigning
number,string, andbooleantypes
- Purpose: Shows how to work with arrays in TypeScript.
- Topics Covered:
- Declaring arrays of specific types
- Readonly arrays
- Arrays with mixed types
- Purpose: Explains how to define and use object types.
- Topics Covered:
- Object property typing
- Optional properties
- Accessing and modifying object properties
- Purpose: Introduces special types in TypeScript.
- Topics Covered:
- The
anytype and its risks - The
unknowntype and safe usage patterns
- The
- Purpose: Provides examples of using tuples.
- Topics Covered:
- Tuple declaration and access
- Readonly tuples
- Type-safe element access
To run the examples in this repository:
-
Install dependencies:
npm install
-
Compile TypeScript files:
npx tsc
-
Run an example file:
node TypeScript_SimpleTypes/TypeAssignment.js
🔎 Check lint issues npx eslint . --ext .ts 🛠️ Auto-fix lint issues npx eslint . --ext .ts --fix 🎨 Format with Prettier npx prettier --write .
- ESLint catches errors and enforces rules such as:
- Missing await in Playwright actions (playwright/missing-playwright-await)
- Unused variables (@typescript-eslint/no-unused-vars)
- Forgotten promises (@typescript-eslint/no-floating-promises)
- Prettier enforces consistent formatting (quotes, semicolons, indentation, etc.)
- Integration: ESLint is configured to run Prettier as a rule (prettier/prettier).