TypeScript · Senior · Question 33 of 75

How do you check a type in tests so that you get an error if there's NO compile error?

Explanation

@ts-expect-error suppresses an error and itself becomes an error if there's nothing to suppress - so a type test "fails" when a type becomes too wide. @ts-ignore is always silent and hides problems. For assertions there's expectTypeOf in Vitest, tsd, and @ts-expect-error in type-challenges.

Further reading

Problem with a question

TypeScript · Senior · question 33

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz