A comprehensive demonstration of TypeScript language features, showcasing everything from basic types to advanced type manipulation.
This repository contains KitchenSink.ts
, a single TypeScript file that demonstrates virtually every TypeScript language feature. It serves as a reference guide and learning resource for TypeScript developers.
- Primitive types (boolean, number, string, bigint, symbol, undefined, null)
- Arrays and tuples
- Object types and index signatures
- Function types
- Union types for either/or scenarios
- Intersection types for combining types
- Discriminated unions for type-safe pattern matching
- String, numeric, and boolean literals
- Template literal types for string pattern matching
- Creating custom type aliases
- Interface definitions and extensions
- Interface merging
- Hybrid types
- Generic functions and constraints
- Generic interfaces and classes
- Generic type aliases
- Utility types usage
- Class inheritance and access modifiers
- Abstract classes
- Static members
- Parameter properties
- Getters and setters
- Numeric, string, and heterogeneous enums
- Const enums for performance optimization
- Type guards and predicates
- Conditional types
- Mapped types
- Index access types
- Partial, Required, Readonly
- Pick, Omit, Record
- Exclude, Extract, NonNullable
- Parameters, ReturnType, InstanceType
- And many more...
- Namespace organization
- Module augmentation
- Global augmentation
- Class, method, property, and parameter decorators
- Function overloading
- Rest parameters
- This parameters
- Call and construct signatures
- Type assertions
- Const assertions
- Type narrowing techniques
- Exhaustiveness checking
- Unique symbols
- Well-known symbols
- Iterator implementation
- Promises
- Async/await
- Async generators
- Mixin pattern implementation
- Composing behaviors
- Reference directives for type definitions
- keyof and typeof operators
- Indexed access types
- Template literal types
- Intrinsic string manipulation
- Covariance, contravariance, invariance, and bivariance
- Object and array destructuring with types
- Rest patterns
- Destructuring in function parameters
- Type validation without type assertion
- Preserving literal types in generic functions
- Resource management with automatic disposal
- Various module export/import strategies
- Type-only imports/exports
- Interface and namespace merging
- Node.js (v14 or higher)
- TypeScript (v5.0 or higher recommended)
- Clone the repository:
git clone https://github.com/devrelopers/Kitchen-Sink-TypeScript.git
cd Kitchen-Sink-TypeScript
- Install TypeScript (if not already installed):
npm install -g typescript
To compile the TypeScript file:
tsc KitchenSink.ts
This will generate a KitchenSink.js
file.
After compilation:
node KitchenSink.js
For best results, create a tsconfig.json
file:
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
This kitchen sink file is useful for:
- Learning TypeScript: Explore various TypeScript features in one place
- Reference Guide: Quick lookup for TypeScript syntax and patterns
- Testing TypeScript Compilers: Verify compiler behavior with comprehensive features
- Code Examples: Copy and adapt examples for your own projects
- Interview Preparation: Review TypeScript concepts
- Teaching: Demonstrate TypeScript capabilities to others
Feel free to submit issues or pull requests if you find any TypeScript features that are missing or could be better demonstrated.
MIT License - Feel free to use this code for learning and reference purposes.
This kitchen sink is inspired by the TypeScript documentation and community best practices. It aims to be a comprehensive showcase of TypeScript's powerful type system and language features.
Current Version: 1.0.0
Note: Some features (like decorators) may require specific TypeScript compiler flags to be enabled. Refer to the TypeScript documentation for the latest feature support and configuration requirements.