To create a default TypeScript configuration file, run:
tsc --initThis will generate a tsconfig.json in your project root. You can customize it as needed.
To compile all .ts files according to your tsconfig.json settings:
tscThis will output compiled .js files to the folder specified in outDir (e.g., dist).
Use Node.js to run the output file. For example:
node .\dist\arraysAndTuples.jsReplace the filename with the desired compiled file.
- Demonstrates arrays, tuples, readonly arrays/tuples, and updating tuple values.
- Example: storing student data and updating scores.
- Shows how to use interfaces as contracts for classes, and how classes implement interfaces.
- Example:
Shapeinterface,RectangleandCircleclasses.
- Covers type aliases for tuples and objects, and usage of enums for named constants.
- Example:
Studenttuple,Animalobject,Directionenum.
- Explains function type annotations, optional/default/rest parameters, and a practical calculator function using union types.
- Demonstrates literal types (string, number, boolean) and unions of literals for strict value constraints.
- Shows optional chaining and nullish coalescing for safe property access and default values in objects with optional properties.
- Covers object types, readonly properties, and index signatures for flexible property addition.
- Example:
EmployeeandProducttypes.
- Explains variable type declarations, union types,
anytype, and type aliases for custom variable types.
Each file is self-contained and can be compiled and run to see the output and TypeScript features in action.