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..
Currently I've completed 137 challenges. You can check them out, in order, below:
- 00013 - Hello World
- 00014 - First
- 0011 - Tuple to Object
- 0018 - Tuple Length
- 00043 - Exclude
- 0043 - Exclude
- 00189 - Awaited
- 00268 - If
- 00533 - Concat
- 00898 - Includes
- 03057 - Push
- 03060 - Unshift
- 03312 - Parameters
- 00002 - ReturnType
- 00003 - Omit
- 00004 - Pick
- 00007 - Readonly
- 00008 - Readonly2
- 00009 - DeepReadonly
- 00010 - Tuple to Union
- 00012 - Chainable
- 00015 - Last Array Item
- 00016 - Pop
- 00020 - Promise All
- 00062 - Lookup
- 00106 - TrimLeft'
- 00108 - Trim
- 00110 - Capitalize
- 00116 - Replace
- 00119 - ReplaceAll
- 00191 - Append Argument
- 00296 - Permutation
- 00298 - String Length
- 00459 - Flatten
- 00527 - Append to Obj
- 00529 - Absolute
- 00531 - String to Union
- 00599 - Obj Merge
- 00612 - Kebab Case
- 00645 - Obj Diff
- 00949 - AnyOf
- 01042 - IsNever
- 01097 - IsUnion
- 01130 - Replace Keys
- 01367 - Remove Index Signature
- 01978 - Percentage Parser
- 02070 - Drop Char
- 02257 - Minus 1
- 02595 - Pick By Type
- 02688 - StartsWith
- 02693 - EndsWith
- 02757 - Partial By Keys
- 02759 - Required By Keys
- 02793 - Mutable Obj
- 02852 - Omit By Type
- 02946 - Object Entries
- 03062 - Shift
- 03188 - Tuple to Nested Object
- 03192 - Reverse
- 03196 - Flip Arguments
- 03243 - Flat Depth
- 03326 - BEM Style
- 03376 - InorderTraversal
- 04179 - Flip Key-Values
- 04260 - All combinations
- 04425 - Greater Than
- 04471 - Zip
- 04484 - IsTuple
- 04499 - Chunk
- 04518 - Fill
- 04803 - TrimRight
- 05117 - Without
- 05140 - Truncate
- 05153 - IndexOf
- 05310 - Join
- 05317 - LastIndexOf
- 05360 - Unique
- 05821 - MapTypesSwap
- 07544 - ConstructTuple
- 08640 - Number Range
- 08767 - Combination
- 08987 - Subsequence
- 09896 - Get Middle Element
- 10969 - Integer
- 16259 - To Primitive
- 17973 - DeepMutable
- 00017 - Currying 1
- 00055 - Union To Intersection
- 00057 - Get Required
- 00059 - Get Optional
- 00089 - Required Keys
- 00090 - Optional Keys
- 00112 - Capitalize Words
- 00114 - Cammelcase
- 00147 - C-printf Parser
- 00223 - IsAny
- 00006 - Simple Vue
- 00213 - Vue Basic Props
- 00270 - Typed Get
- 00300 - String to Number
- 00399 - Tuple Filter
- 00472 - Tuple to Enum Obj
- 00545 - PrintF
- 00553 - Object unique
- 00651 - Length of string 2
- 00730 - Union to Tuple
- 00847 - String Join
- 00956 - Deep Pick
- 01290 - Pinia
- 01383 - Camelize
- 02059 - Drop String
- 02822 - Split
- 02828 - Class Public Keys
- 02857 - IsRequired Key
- 02949 - Object from Entries
- 04037 - Is Palindrome
- 05181 - Mutable Keys
- 05423 - Intersection
- 06141 - Binary to Decimal
- 07258 - Object Key Paths
- 08804 - Two Sum
- 09155 - Valid Date
- 09160 - Assign
- 09775 - Capitalize Object Keys
- 14188 - Run Length Encoding
- 15260 - Tree Path
- 00005 - Readonly Keys
- 00151 - Query String Parser
- 00216 - Slice
- 00274 - Integers Comparator
- 00462 - Extreme Curring
- 00476 - Sum
- 00517 - Multiply
- 00697 - Tag
- 00734 - Inclusive Range
- 00741 - Sort
- 00869 - Distribute Unions
- 06228 - JSON Parser
- 07561 - Subtract
- xxxx - Next
- Clone the repository
- Run
npm install
oryarn
orpnpm install
- 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
-
X extends Y
can be read as "is X a subset of Y" -
IsAny
check visualizedtype 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 valueunknown & some_type
=some_type
-
never
is "ignored" on unions that contain valuenever | string
=string
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;
}