JavaScript & TypeScript / Scenario
The Cast That Smuggled a Regression
tsc is green, tests are green, production renders 'undefined'. Trace how two innocent-looking casts disarmed the type system exactly where it was needed.
- Difficulty
- Hard
- Format
- Scenario
- Points
- 200
- Estimate
- 14 min
// MISSION BRIEF
Your Mission
A rename refactor changed the User type. The compiler blessed it. The tests blessed it. The profile page now greets everyone as undefined.
Read the test file and the refactor diff. Work out why TypeScript never flagged the stale test data, and rebuild the mocks and fixtures so the compiler is back on guard duty.
// FIRST CONTACT
Battle teaser
First artifact
user-card.test.tsx (green before AND after the refactor)
Why did tsc stay silent about the mock returning { name } when User now requires displayName?
- Ajest.mock erases types at runtime, so the compiler skips mocked modules
- BBoth casts erase the contract: 'as jest.Mock' forgets fetchUser's signature entirely, and 'as unknown as User' force-approves any object shape, so no assignment was ever checked against the new User
- Ctsc does not check test files unless they are in src/
- DThe User type change was in a different file, and cross-file checks require project references
Answers, scoring, hints, and the full battle stay sealed.
// SKILL TAGS
typescriptmockingjestvitesttype-safety