A comprehensive collection of TypeScript programming examples covering fundamental to advanced concepts. This repository contains 31+ TypeScript source files that demonstrate various aspects of the TypeScript language, from basic syntax to advanced features like generics, promises, and modules.
- Overview
- Prerequisites
- Installation
- Usage
- Topics Covered
- Running the Examples
- File Organization
- Contributing
- License
- Author
This TypeScript Learning Pack is designed for developers who want to learn or improve their TypeScript skills. Each file focuses on a specific concept with practical examples and clear explanations. The examples progress from basic language constructs to advanced TypeScript features.
Before running these examples, ensure you have the following installed:
- Node.js 14 or higher
- TypeScript compiler (tsc)
- npm or yarn package manager
- Code editor (VS Code recommended) or any TypeScript-compatible IDE
# Check Node.js version
node --version
# Check TypeScript compiler
tsc --version
# Check npm version
npm --version-
Clone the repository:
git clone https://github.com/raushan728/Typescript-language.git cd TypeScript-learning -
Open VS Code
-
Install the recommended extensions:
- TypeScript and JavaScript Language Features
- Code Runner (optional for easy execution)
-
Clone the repository:
git clone https://github.com/raushan728/Typescript-language.git cd TypeScript-learning -
Install TypeScript compiler if not already installed:
Check if you have package managers installed:
# Check for winget (Windows Package Manager)
winget --version
# Check for Chocolatey
choco --versionInstall via winget (recommended):
# Install Node.js
winget install OpenJS.NodeJS
# Install TypeScript globally
npm install -g typescriptInstall via Chocolatey:
# Install Node.js
choco install nodejs
# Install TypeScript globally
npm install -g typescriptManual installation:
- Download Node.js from nodejs.org
- Install TypeScript globally:
npm install -g typescript
# Install via Homebrew
brew install node
# Install TypeScript globally
npm install -g typescript# Install Node.js via package manager
# Ubuntu/Debian:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# Fedora:
sudo dnf install nodejs
# Arch Linux:
sudo pacman -S nodejs npm
# Install TypeScript globally
sudo npm install -g typescript- Install Code Runner extension
- Right-click on any
.tsfile - Select "Run Code" or use keyboard shortcut
# Compile a TypeScript file
tsc filename.ts
# Run the compiled JavaScript
node filename.js
# Example:
tsc 01_Comments_And_Syntax.ts
node 01_Comments_And_Syntax.js# Install ts-node globally
npm install -g ts-node
# Run TypeScript files directly
ts-node filename.ts
# Example:
ts-node 01_Comments_And_Syntax.ts# Create tsconfig.json for project compilation
tsc --init
# Compile all TypeScript files
tsc
# Run specific compiled files
node dist/filename.jsThe repository is organized to cover TypeScript concepts in a progressive manner:
- 01_Comments_And_Syntax.ts - Comments, basic syntax, and code structure
- 02_Variables_And_Types.ts - Variable declarations and basic types
- 03_Type_Inference_And_Annotations.ts - Type inference and explicit annotations
- 04_Operators.ts - Arithmetic, comparison, and logical operators
- 05_Conditionals.ts - if-else statements and switch cases
- 06_Loops.ts - For, while, and do-while loops
- 07_Functions.ts - Function declarations, parameters, and return types
- 08_Arrays.ts - Array operations and methods
- 09_Tuples.ts - Tuple types and usage
- 10_Enums.ts - Enum types and their applications
- 11_Objects.ts - Object types and structures
- 12_Any_Unknown.ts - any and unknown type differences
- 13_Type_Aliases.ts - Creating custom type aliases
- 14_Union_Intersection.ts - Union and intersection types
- 15_Literal_Types.ts - Literal type constraints
- 16_Null_Undefined.ts - Handling null and undefined
- 17_Type_Assertions.ts - Type assertions and casting
- 18_Interfaces.ts - Interface declarations and implementations
- 19_Classes.ts - Class definitions and instances
- 20_Objects_with_Interface.ts - Using interfaces with objects
- 21_Readonly_Optional.ts - Readonly and optional properties
- 22_Constructor_Public_Private.ts - Access modifiers in classes
- 23_Static_Properties_Methods.ts - Static class members
- 24_Inheritance.ts - Class inheritance patterns
- 25_Abstract_Class.ts - Abstract classes and methods
- 26_Interface_vs_Type.ts - Interface vs Type alias comparison
- 31_Extends_Keyword.ts - extends keyword usage
- 27_Generics.ts - Generic types and functions
- 28_Promises.ts - Promise handling and async/await
- 29_Modules.ts - Module import/export patterns
- 30_Practice_Questions.ts - Practical coding exercises
Each file is self-contained and can be run independently. The files include:
- Main code - Practical examples demonstrating each concept
- Comments - Detailed explanations of TypeScript features
- Type annotations - Comprehensive type definitions
- Best practices - Industry-standard coding patterns
- Start with basics: Begin with
01_Comments_And_Syntax.tsand progress sequentially - Experiment: Modify the code and observe type checking behavior
- Practice: Create your own variations of the examples
- Reference: Use files as reference for your own TypeScript projects
The repository contains 31 TypeScript files organized sequentially from basic to advanced concepts. Each file is numbered and focuses on a specific TypeScript topic, making it easy to follow the learning progression.
Contributions are welcome! If you find any issues or want to add more examples:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-example) - Commit your changes (
git commit -am 'Add new example') - Push to the branch (
git push origin feature/new-example) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Raushan Kumar
Happy Learning!