Skip to content

devrelopers/Kitchen-Sink-TypeScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

TypeScript Kitchen Sink

A comprehensive demonstration of TypeScript language features, showcasing everything from basic types to advanced type manipulation.

Overview

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.

Features Covered

1. Basic Types

  • Primitive types (boolean, number, string, bigint, symbol, undefined, null)
  • Arrays and tuples
  • Object types and index signatures
  • Function types

2. Union and Intersection Types

  • Union types for either/or scenarios
  • Intersection types for combining types
  • Discriminated unions for type-safe pattern matching

3. Literal Types

  • String, numeric, and boolean literals
  • Template literal types for string pattern matching

4. Type Aliases and Interfaces

  • Creating custom type aliases
  • Interface definitions and extensions
  • Interface merging
  • Hybrid types

5. Generics

  • Generic functions and constraints
  • Generic interfaces and classes
  • Generic type aliases
  • Utility types usage

6. Classes

  • Class inheritance and access modifiers
  • Abstract classes
  • Static members
  • Parameter properties
  • Getters and setters

7. Enums

  • Numeric, string, and heterogeneous enums
  • Const enums for performance optimization

8. Advanced Types

  • Type guards and predicates
  • Conditional types
  • Mapped types
  • Index access types

9. Utility Types

  • Partial, Required, Readonly
  • Pick, Omit, Record
  • Exclude, Extract, NonNullable
  • Parameters, ReturnType, InstanceType
  • And many more...

10. Modules and Namespaces

  • Namespace organization
  • Module augmentation
  • Global augmentation

11. Decorators (Experimental)

  • Class, method, property, and parameter decorators

12. Advanced Function Features

  • Function overloading
  • Rest parameters
  • This parameters
  • Call and construct signatures

13. Type Assertions and Narrowing

  • Type assertions
  • Const assertions
  • Type narrowing techniques
  • Exhaustiveness checking

14. Symbols and Iterators

  • Unique symbols
  • Well-known symbols
  • Iterator implementation

15. Async Patterns

  • Promises
  • Async/await
  • Async generators

16. Mixins

  • Mixin pattern implementation
  • Composing behaviors

17. Triple-Slash Directives

  • Reference directives for type definitions

18. Type Manipulation

  • keyof and typeof operators
  • Indexed access types
  • Template literal types
  • Intrinsic string manipulation

19. Variance

  • Covariance, contravariance, invariance, and bivariance

20. Pattern Matching and Destructuring

  • Object and array destructuring with types
  • Rest patterns
  • Destructuring in function parameters

21. Satisfies Operator

  • Type validation without type assertion

22. Const Type Parameters

  • Preserving literal types in generic functions

23. Using Declarations

  • Resource management with automatic disposal

24. Export and Import Patterns

  • Various module export/import strategies
  • Type-only imports/exports

25. Declaration Merging

  • Interface and namespace merging

Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • TypeScript (v5.0 or higher recommended)

Installation

  1. Clone the repository:
git clone https://github.com/devrelopers/Kitchen-Sink-TypeScript.git
cd Kitchen-Sink-TypeScript
  1. Install TypeScript (if not already installed):
npm install -g typescript

Compiling the Code

To compile the TypeScript file:

tsc KitchenSink.ts

This will generate a KitchenSink.js file.

Running the Code

After compilation:

node KitchenSink.js

TypeScript Configuration

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
  }
}

Use Cases

This kitchen sink file is useful for:

  1. Learning TypeScript: Explore various TypeScript features in one place
  2. Reference Guide: Quick lookup for TypeScript syntax and patterns
  3. Testing TypeScript Compilers: Verify compiler behavior with comprehensive features
  4. Code Examples: Copy and adapt examples for your own projects
  5. Interview Preparation: Review TypeScript concepts
  6. Teaching: Demonstrate TypeScript capabilities to others

Contributing

Feel free to submit issues or pull requests if you find any TypeScript features that are missing or could be better demonstrated.

License

MIT License - Feel free to use this code for learning and reference purposes.

Acknowledgments

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.

Version

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.

About

Everything in TS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •