TypeScriptIntermediateMedium severity
Type is not assignable to type
A value's inferred or declared shape does not satisfy the type required at that location.
5-20 min Popularity 93/100 Verified 2026-07-21
What does this error mean?
TypeScript compared the source value with the destination type and found at least one incompatible property, union member, or generic constraint.
Why does this happen?
- A property is missing or has the wrong type.
- A string was widened instead of inferred as a literal.
- A value can be null or undefined.
- Two similar types come from different package versions.
- A generic constraint is too narrow.
AI explanation
Plain-English analysis
TypeScript is showing where the contract and the value disagree. Read the message from the deepest nested incompatibility upward; that final detail is usually more useful than the headline.
Quick fix
Terminal
Inspect the full compiler message. Fix the source value or update the destination contract.
Expected output: The compiler accepts the assignment without a type assertion.
Step-by-step fix
1Make the value satisfy the required typeAdd the missing property or transform the value before assignment.75%
2Handle nullability explicitlyNarrow optional values before passing them to code that requires a concrete value.58%
3Correct the type definitionIf the runtime value is valid, update an inaccurate or overly narrow type.39%
Alternative solutions
Strict TypeScript
Use a type guard before assignment.
Prefer narrowing over `as` assertions.
External data
Validate the response at runtime before treating it as typed.
Type annotations do not validate API responses.
Real example
Broken
typescript
type Status = "open" | "closed"; const status: Status = getValue(); // string
Corrected
typescript
type Status = "open" | "closed";
function isStatus(value: string): value is Status {
return value === "open" || value === "closed";
}
const value = getValue();
if (isStatus(value)) {
const status: Status = value;
}Frequently asked questions
A type assertion silences the compiler without changing the runtime value. Use it only when you have stronger knowledge than TypeScript and can justify that knowledge.