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?
- ✓Correct answer:
// @ts-expect-errorabove the line being checked - 2
// @ts-ignoreabove the line being checked - 3
// @ts-nocheckat the top of the test file
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.