Skip to content

fabiosenracorrea/ts-type-challenges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0ed9fa2 · Mar 12, 2025
Feb 28, 2025
Mar 12, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Mar 12, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Mar 12, 2025
Feb 28, 2025
Mar 12, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025
Feb 28, 2025

Repository files navigation

Typescript Type Challenges

This repo captures the TS challenges from type-challenges

Last synced: 2025-02-28

These challenges were done with no cheating of the solution, with the exception of those that explicitly reference a source on it. Some of them contain extra types that could be derived from the main type idea or multiple solutions that either consider multiple use-cases or all solve it

The difficulty level comes from the repo itself. Some of the ratings are quite questionable. Example, "Includes" and "Push" both marked as easy does not make that much sense. Anyway..

Completed Challenges

Currently I've completed 137 challenges. You can check them out, in order, below:

Sorted Challenge List (by Completion Order)

How to validate

  1. Clone the repository
  2. Run npm install or yarn or pnpm install
  3. Access the challenge to verify no errors are present

Later will add a "run all completed" script to facilitate that work, but the ideia here is to individually look at the approaches, instead of blindly seeing that it simply pass all

Worthy Concepts along the way

Quickbits

  • X extends Y can be read as "is X a subset of Y"

  • IsAny check visualized

    type IsAny<T> = 1 extends T & 0 ? true : false
    
    type A = any & 0 // any
    type B = never & 0 // never
    type C = unknown & 0 // 0
  • unknown is "ignored" on intersections that contain value unknown & some_type = some_type

  • never is "ignored" on unions that contain value never | string = string

Key casting

We are familiar with the object mapping we can use:

type SomeKeys = 'name' | 'age'

type Person = {
  [K in SomeKeys]: string
}

// Creates:

type Person = {
  name: string;
  age: string;
}

We can use as to remap inside the bracket declaration if we need to act on a condition:

type SomeKeys = 'name' | 'age'

type Person = {
  [K in SomeKeys as K extends 'name' ? never : K]: string
}

// Creates:

type Person = {
  age: string;
}

About

Test how deep your knowledge on Typescript types go!

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Languages