Top Related Projects
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹
Cheatsheets for experienced React developers getting started with TypeScript
An interactive TypeScript tutorial for beginners
A collection of essential TypeScript types
Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
Quick Overview
Type Challenges is a collection of TypeScript type puzzles designed to help developers improve their TypeScript skills. It offers a wide range of challenges, from beginner to advanced levels, focusing on type manipulation and advanced TypeScript features.
Pros
- Provides hands-on practice for TypeScript type system
- Covers a wide range of difficulty levels, suitable for beginners to experts
- Encourages community contributions and discussions
- Regularly updated with new challenges
Cons
- May be overwhelming for complete beginners to TypeScript
- Some challenges can be highly complex and theoretical
- Limited practical application for certain advanced challenges
- Requires a solid understanding of TypeScript to fully benefit
Code Examples
- Easy challenge: Pick
// Implement the built-in Pick<T, K> generic without using it.
type MyPick<T, K extends keyof T> = {
[P in K]: T[P];
};
- Medium challenge: Promise.all
// Type the function PromiseAll that accepts an array of PromiseLike objects, the returning value should be Promise<T> where T is the resolved result array.
declare function PromiseAll<T extends any[]>(
values: readonly [...T]
): Promise<{ [K in keyof T]: T[K] extends PromiseLike<infer R> ? R : T[K] }>;
- Hard challenge: Currying
// Implement the type version of currying.
type Curry<F> = F extends (...args: infer A) => infer R
? A extends [infer First, ...infer Rest]
? (arg: First) => Curry<(...args: Rest) => R>
: R
: never;
Getting Started
- Visit the Type Challenges repository
- Choose a challenge based on your skill level (Easy, Medium, Hard, or Extreme)
- Open the challenge in the TypeScript Playground or your local development environment
- Implement the type as requested in the challenge description
- Run the provided test cases to verify your solution
- Compare your solution with others or discuss in the comments section
Competitor Comparisons
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
Pros of TypeScript
- Official repository for the TypeScript language, providing the most up-to-date and authoritative source code
- Comprehensive documentation, including language specification, release notes, and roadmap
- Active development with frequent updates and bug fixes
Cons of TypeScript
- Larger codebase, which may be overwhelming for beginners or those looking to contribute
- Focus on language implementation rather than learning exercises or challenges
- Less emphasis on community-driven content and problem-solving
Code Comparison
TypeScript (compiler implementation):
function createDiagnostic(node: Node, message: DiagnosticMessage, ...args: any[]): DiagnosticWithLocation {
const diagnostic = createDiagnosticForNode(node, message, ...args);
return diagnostic;
}
Type Challenges (example challenge):
type HelloWorld = string // expected to be a string
Summary
TypeScript is the official repository for the TypeScript language, offering comprehensive documentation and frequent updates. However, it may be overwhelming for beginners and lacks focus on learning exercises. Type Challenges, on the other hand, provides a collection of TypeScript type challenges for learning and practice, with a more community-driven approach. The code comparison illustrates the difference in focus, with TypeScript showing language implementation details and Type Challenges presenting concise learning exercises.
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹
Pros of typescript-book
- Comprehensive learning resource covering TypeScript concepts and best practices
- Structured content with clear explanations and examples
- Suitable for beginners and intermediate developers
Cons of typescript-book
- Less hands-on practice compared to type-challenges
- May not cover advanced type manipulation techniques as extensively
- Static content that may not be updated as frequently as community-driven challenges
Code Comparison
typescript-book example:
interface Person {
name: string;
age: number;
}
function greet(person: Person) {
return `Hello, ${person.name}!`;
}
type-challenges example:
type HelloWorld<T> = T extends string ? `Hello, ${T}!` : never;
// Expected: "Hello, World!"
type result = HelloWorld<'World'>;
The typescript-book example demonstrates basic interface and function typing, while the type-challenges example showcases advanced type manipulation using conditional types and template literal types.
typescript-book provides a more traditional learning approach with explanations and examples, while type-challenges offers hands-on practice with increasingly complex type puzzles. Both repositories serve different purposes in the TypeScript learning ecosystem, with typescript-book being more suitable for beginners and type-challenges catering to those looking to deepen their understanding of TypeScript's type system.
Cheatsheets for experienced React developers getting started with TypeScript
Pros of react
- Focuses specifically on React and TypeScript integration
- Provides practical, real-world examples and best practices
- Offers a comprehensive cheatsheet format for quick reference
Cons of react
- Less emphasis on advanced TypeScript concepts
- May not cover as wide a range of TypeScript challenges
- Could become outdated as React and TypeScript evolve
Code Comparison
type-challenges:
type HelloWorld = string
type test = Expect<Equal<HelloWorld, string>>
react:
interface Props {
name: string;
age: number;
}
const MyComponent: React.FC<Props> = ({ name, age }) => {
return <div>{name} is {age} years old</div>;
}
The type-challenges example focuses on pure TypeScript type manipulation, while the react example demonstrates practical TypeScript usage within a React component.
type-challenges offers a wide range of TypeScript puzzles and challenges, helping users deepen their understanding of the language's type system. It's excellent for honing advanced TypeScript skills and exploring edge cases.
react, on the other hand, provides a more applied approach, focusing on how to effectively use TypeScript in React projects. It offers guidelines, patterns, and best practices specific to React development with TypeScript.
Both repositories serve different purposes and can be complementary in a developer's learning journey. type-challenges is ideal for mastering TypeScript's type system, while react is more suitable for practical application in React projects.
An interactive TypeScript tutorial for beginners
Pros of beginners-typescript-tutorial
- More beginner-friendly, with a structured learning path
- Includes video tutorials for visual learners
- Focuses on practical, real-world TypeScript usage
Cons of beginners-typescript-tutorial
- Less comprehensive coverage of advanced TypeScript features
- Fewer challenges overall, limiting practice opportunities
- May not be as suitable for experienced TypeScript developers
Code Comparison
beginners-typescript-tutorial:
interface User {
id: number;
name: string;
email: string;
}
function getUserInfo(user: User): string {
return `${user.name} (${user.email})`;
}
type-challenges:
type GetReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
type Result = GetReturnType<() => string>; // Result is string
type ComplexResult = GetReturnType<(a: number, b: string) => boolean>; // ComplexResult is boolean
Summary
beginners-typescript-tutorial is ideal for newcomers to TypeScript, offering a structured approach with video content and focusing on practical applications. However, it may not delve as deeply into advanced topics as type-challenges.
type-challenges provides a more comprehensive set of challenges, covering a wider range of TypeScript features and complexities. It's better suited for developers looking to push their TypeScript skills to the limit, but may be overwhelming for beginners.
Choose based on your current TypeScript proficiency and learning goals.
A collection of essential TypeScript types
Pros of Type Fest
- Type Fest provides a comprehensive collection of commonly used TypeScript types, making it a valuable resource for developers.
- The library is actively maintained and regularly updated, ensuring compatibility with the latest TypeScript versions.
- Type Fest includes a wide range of utility types, such as
Awaited
,Promisable
, andPrimitive
, which can save developers time and effort.
Cons of Type Fest
- Type Fest may be overkill for smaller projects that only require a few specific types.
- The library can be more difficult to navigate compared to the more focused Type Challenges repository.
- Some developers may prefer to create their own custom types rather than relying on a third-party library.
Code Comparison
Type Challenges:
type Includes<T extends readonly any[], U> = T extends [infer F, ...infer R]
? Equal<F, U> extends true
? true
: Includes<R, U>
: false;
Type Fest:
type Includes<T extends readonly any[], U> = T extends [infer F, ...infer R]
? Equal<F, U> extends true
? true
: Includes<R, U>
: false;
As you can see, the implementation of the Includes
type is very similar between the two repositories, demonstrating the overlap in the types they provide.
Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
Pros of utility-types
- Ready-to-use utility types for immediate implementation in projects
- Comprehensive documentation with examples for each utility type
- Actively maintained with regular updates and improvements
Cons of utility-types
- Less focus on learning and understanding complex type manipulations
- Fewer community contributions and discussions compared to type-challenges
- May lead to over-reliance on pre-built utilities instead of custom solutions
Code Comparison
type-challenges:
// Implement a type that adds two numbers
type Add<A extends number, B extends number> = [
...TupleOf<A>, ...TupleOf<B>
]['length'];
utility-types:
// Pre-defined utility type for non-nullable types
type NonNullable<T> = T extends null | undefined ? never : T;
Summary
type-challenges focuses on learning and practicing advanced TypeScript concepts through challenges, fostering a deeper understanding of the type system. It encourages community engagement and problem-solving skills.
utility-types provides a collection of ready-made utility types for immediate use in projects. It offers well-documented, practical solutions but may not emphasize the learning aspect as much as type-challenges.
Choose type-challenges for improving TypeScript skills and understanding complex type manipulations. Opt for utility-types when seeking efficient, pre-built solutions for common type scenarios in projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Collection of TypeScript type challenges
English | ç®ä½ä¸æ | æ¥æ¬èª | íêµì´ | Português
Intro
by the power of TypeScript's well-known Turing Completed type system
High-quality types can help improve projects' maintainability while avoiding potential bugs.
There are a bunch of awesome type utility libraries that may boost your works on types, like ts-toolbelt, utility-types, SimplyTyped, etc., which you can already use.
This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges. We are also trying to form a community where you can ask questions and get answers you have faced in the real world - they may become part of the challenges!
Challenges
Click the following badges to see details of the challenges.
Note: Challenges work in the strict mode.
By Plain Text
warm-up (1)
easy (13)
- 4ã»Pick
- 7ã»Readonly
- 11ã»Tuple to Object
- 14ã»First of Array
- 18ã»Length of Tuple
- 43ã»Exclude
- 189ã»Awaited
- 268ã»If
- 533ã»Concat
- 898ã»Includes
- 3057ã»Push
- 3060ã»Unshift
- 3312ã»Parameters
medium (98)
- 2ã»Get Return Type
- 3ã»Omit
- 8ã»Readonly 2
- 9ã»Deep Readonly
- 10ã»Tuple to Union
- 12ã»Chainable Options
- 15ã»Last of Array
- 16ã»Pop
- 20ã»Promise.all
- 62ã»Type Lookup
- 106ã»Trim Left
- 108ã»Trim
- 110ã»Capitalize
- 116ã»Replace
- 119ã»ReplaceAll
- 191ã»Append Argument
- 296ã»Permutation
- 298ã»Length of String
- 459ã»Flatten
- 527ã»Append to object
- 529ã»Absolute
- 531ã»String to Union
- 599ã»Merge
- 612ã»KebabCase
- 645ã»Diff
- 949ã»AnyOf
- 1042ã»IsNever
- 1097ã»IsUnion
- 1130ã»ReplaceKeys
- 1367ã»Remove Index Signature
- 1978ã»Percentage Parser
- 2070ã»Drop Char
- 2257ã»MinusOne
- 2595ã»PickByType
- 2688ã»StartsWith
- 2693ã»EndsWith
- 2757ã»PartialByKeys
- 2759ã»RequiredByKeys
- 2793ã»Mutable
- 2852ã»OmitByType
- 2946ã»ObjectEntries
- 3062ã»Shift
- 3188ã»Tuple to Nested Object
- 3192ã»Reverse
- 3196ã»Flip Arguments
- 3243ã»FlattenDepth
- 3326ã»BEM style string
- 3376ã»InorderTraversal
- 4179ã»Flip
- 4182ã»Fibonacci Sequence
- 4260ã»AllCombinations
- 4425ã»Greater Than
- 4471ã»Zip
- 4484ã»IsTuple
- 4499ã»Chunk
- 4518ã»Fill
- 4803ã»Trim Right
- 5117ã»Without
- 5140ã»Trunc
- 5153ã»IndexOf
- 5310ã»Join
- 5317ã»LastIndexOf
- 5360ã»Unique
- 5821ã»MapTypes
- 7544ã»Construct Tuple
- 8640ã»Number Range
- 8767ã»Combination
- 8987ã»Subsequence
- 9142ã»CheckRepeatedChars
- 9286ã»FirstUniqueCharIndex
- 9616ã»Parse URL Params
- 9896ã»GetMiddleElement
- 9898ã»Appear only once
- 9989ã»Count Element Number To Object
- 10969ã»Integer
- 16259ã»ToPrimitive
- 17973ã»DeepMutable
- 18142ã»All
- 18220ã»Filter
- 21104ã»FindAll
- 21106ã»Combination key type
- 21220ã»Permutations of Tuple
- 25170ã»Replace First
- 25270ã»Transpose
- 26401ã»JSON Schema to TypeScript
- 27133ã»Square
- 27152ã»Triangular number
- 27862ã»CartesianProduct
- 27932ã»MergeAll
- 27958ã»CheckRepeatedTuple
- 28333ã»Public Type
- 29650ã»ExtractToObject
- 29785ã»Deep Omit
- 30301ã»IsOdd
- 30430ã»Tower of hanoi
- 30958ã»Pascal's triangle
- 30970ã»IsFixedStringLiteralType
- 34007ã»Compare Array Length
hard (53)
- 6ã»Simple Vue
- 17ã»Currying 1
- 55ã»Union to Intersection
- 57ã»Get Required
- 59ã»Get Optional
- 89ã»Required Keys
- 90ã»Optional Keys
- 112ã»Capitalize Words
- 114ã»CamelCase
- 147ã»C-printf Parser
- 213ã»Vue Basic Props
- 223ã»IsAny
- 270ã»Typed Get
- 300ã»String to Number
- 399ã»Tuple Filter
- 472ã»Tuple to Enum Object
- 545ã»printf
- 553ã»Deep object to unique
- 651ã»Length of String 2
- 730ã»Union to Tuple
- 847ã»String Join
- 956ã»DeepPick
- 1290ã»Pinia
- 1383ã»Camelize
- 2059ã»Drop String
- 2822ã»Split
- 2828ã»ClassPublicKeys
- 2857ã»IsRequiredKey
- 2949ã»ObjectFromEntries
- 4037ã»IsPalindrome
- 5181ã»Mutable Keys
- 5423ã»Intersection
- 6141ã»Binary to Decimal
- 7258ã»Object Key Paths
- 8804ã»Two Sum
- 9155ã»ValidDate
- 9160ã»Assign
- 9384ã»Maximum
- 9775ã»Capitalize Nest Object Keys
- 13580ã»Replace Union
- 14080ã»FizzBuzz
- 14188ã»Run-length encoding
- 15260ã»Tree path array
- 19458ã»SnakeCase
- 25747ã»IsNegativeNumber
- 28143ã»OptionalUndefined
- 30178ã»Unique Items
- 30575ã»BitwiseXOR
- 31797ã»Sudoku
- 31824ã»Length of String 3
- 32427ã»Unbox
- 32532ã»Binary Addition
- 34286ã»Take Elements
extreme (17)
- 5ã»Get Readonly Keys
- 151ã»Query String Parser
- 216ã»Slice
- 274ã»Integers Comparator
- 462ã»Currying 2
- 476ã»Sum
- 517ã»Multiply
- 697ã»Tag
- 734ã»Inclusive Range
- 741ã»Sort
- 869ã»DistributeUnions
- 925ã»Assert Array Index
- 6228ã»JSON Parser
- 7561ã»Subtract
- 31447ã»CountReversePairs
- 31997ã»Parameter Intersection
- 33345ã»Dynamic Route
ð¥ Start the challenge in TypeScript Playground
ð Start the challenge locally in your IDE or text editor with TypeScript language support
â¡ï¸ Start the challenge in VS Code Extension
Recommended Readings
Official
Articles
- Learn Advanced TypeScript Types
- The Art of Type Programming
- Type Query: jQuery Style Type Manipulation
- TypeScript Deep Dive
Talks
Projects / Solutions
- ð¥ Video Explanations and Solutions for every challenge!
- Type Challenges Solutions
- Type Gymnastics
- TypeType Examples
Books
How to Contribute
There are several ways you can contribute to this project
- Share your answers / solutions
- Propose new challenges
- Add more test cases to the existing challenges
- Provide learning resources or ideas of how to solve challenges
- Share the problems you have faced in real-world projects, regardless you having the solution or not - the community would help you as well
- Help with others by discussion in issues
- Contribute the infra of this project TODOs.md
Just open an issue and choose the corresponding template. Thanks!
Play Locally
You can build the challenges and play locally using your preferred IDE or text editor with TypeScript language support.
To do that, you will need the latest version of Node.js and pnpm installed.
After cloning the repo, installed the dependencies by:
pnpm install
Then and run the generate
script:
pnpm generate
It will prompt you to select the desired language, then you can find the generated challenges in the ./playground
folder.
Later if you want to update playground while keeping your changes:
pnpm generate --keep-changes
OR
pnpm generate -K
Thanks
This project was born from solving real-world types problem with @hardfist and @MeCKodo. And great thanks to @sinoon who contributed a lot while giving early feedback on this project.
Inspired by
Contributors
License
MIT
Top Related Projects
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹
Cheatsheets for experienced React developers getting started with TypeScript
An interactive TypeScript tutorial for beginners
A collection of essential TypeScript types
Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot