This project is a simple TypeScript application designed to demonstrate and explain various fundamental concepts of the TypeScript language. The main logic is contained in the app.ts file, which includes commented code examples.
The app.ts file covers the following TypeScript concepts:
- Basic Types:
string,number,boolean - Arrays:
string[],number[] - Tuples: Fixed-length arrays with specific types.
- Union Types: Variables that can hold multiple types (
string | number). - Special Types:
any,unknown,never. - Functions:
- Basic functions with
voidreturn. - Functions with a
stringreturn type.
- Basic functions with
- Objects:
- Using
interfaceto define object shapes. - Using
typealiases for object shapes.
- Using
- Enums: Creating sets of named constants.
- Classes: Basic class definition with properties, a constructor, and methods.
- Generics: Creating reusable components that can work with a variety of types.
- Intersection Types: Combining multiple types into one.
To compile and run this project, you need to have Node.js and the TypeScript compiler (tsc) installed.
-
Install Dependencies: If you haven't already, install the necessary
typescriptpackage.npm install
-
Compile the TypeScript file: This command compiles the
app.tsfile and generates a correspondingapp.jsfile.npx tsc app.ts
-
Run the JavaScript file: This command executes the compiled JavaScript code using Node.js.
node app.js