Skip to main content

Intro

What is Type Challenges? Type Challenges is a collection of typescript type system puzzles.

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 that you can ask questions and get answers you have faced in the real world - they may become part of the challenges!

View the original github repository for more information.

Why built this#

I always forget how I solved these puzzles, but when I try to figure out how, it's hard to find by Type Challenges UI.

Type Challenges depends on github repository pages which makes hard to jump between different sites.

So I build this site collect all actions of challenge into one place, provides at least one solution and extra type information without navigate to other places.

Start with the Hello World example.

Hello World#

Introduction#

Hello, World!

In Type Challenges, we use the type system itself to do the assertion.

For this challenge, you will need to change the following code to make the tests pass (no type check errors).

ts
// expected to be string
type HelloWorld = any;
ts
// expected to be string
type HelloWorld = any;
note

Go back to the original Type Challenges puzzle start page.

View on GitHub

Start point#

ts
/* _____________ Your Code Here _____________ */
type HelloWorld = any; // expected to be a string
type HelloWorld = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<HelloWorld, string>>
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
]
 
Try
ts
/* _____________ Your Code Here _____________ */
type HelloWorld = any; // expected to be a string
type HelloWorld = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<HelloWorld, string>>
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
]
 
Try
note

Go to the Type Challenges typescript playground page.

take the challenge
tip

this site build with shiki-twoslash

in which markdown code samples are powered by the syntax engine of visual studio code mixed with the typescript compiler’s information

code snippets show type information like this
ts
/* _____________ Your Code Here _____________ */
type HelloWorld = any; // expected to be a string
type HelloWorld = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<HelloWorld, string>>
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
]
 
Try
ts
/* _____________ Your Code Here _____________ */
type HelloWorld = any; // expected to be a string
type HelloWorld = any
 
/* _____________ Test Cases _____________ */
type cases = [
Expect<Equal<HelloWorld, string>>
Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.
]
 
Try

my solutions#

Spoiler warning // Click to reveal answer
ts
type HelloWorld = string;
Try
ts
type HelloWorld = string;
Try
note

Go to the Type Challenges issues to share your answer and other community answers.

view more solutions