Enabling strict mode surfaces errors like 'Type X is not assignable to type Y', especially when passing objects, generics, or union types between functions and components.

TypeScript uses structural typing, so the shapes must match, not just the names. Read the full error carefully, narrow unions with type guards, and use utility types instead of duplicating shapes.

Step-by-Step Guide

1

Read the full error message - TypeScript points to the exact mismatched property

2

Use interface extension instead of duplicating similar type definitions

3

Narrow union types with type guards: typeof, in, or instanceof checks

4

Use the 'satisfies' operator to validate object literals without widening their type

5

Avoid using 'as' to force a type unless you're certain it's safe

6

Constrain generics properly: function foo<T extends SomeShape>(item: T)

7

Use utility types like Partial, Pick, and Omit to reshape existing types

8

Enable strict: true early in a project to catch these issues sooner

Found an issue with this solution?

Related Topics

typescript generics constraintsstrict null checks migrationtype narrowing union types