How to fix Type is not assignable to itself in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025· 124 views

This error occurs when TypeScript detects that two seemingly identical types are actually incompatible, often due to duplicate package versions, circular type references, or complex conditional type inference issues.

Quick fix

Fixes Type is not assignable to itself

npm ls <package-name>
# Example: npm ls @babel/types
  1. Check for duplicate package versions
  2. Use selective version resolution (Yarn)
  3. Use overrides (npm 8.3+)
  4. Clear package manager cache
typescript — error
npm ls <package-name>
# Example: npm ls @babel/types
Type is not assignable to itself

What this error means

The "Type is not assignable to itself" error is one of TypeScript's most confusing messages because it appears to violate basic logic - how can a type not be compatible with itself? This error occurs when TypeScript's type system determines that what appears to be the same type is actually represented by two different, incompatible type instances. The most common cause is duplicate package installations where different versions of the same package create separate type definitions. For example, if you have two versions of @babel/types installed, TypeScript treats TSTypeAliasDeclaration from version 7.4.0 as incompatible with TSTypeAliasDeclaration from version 7.5.0, even though they have the same name. The error can also occur with complex type scenarios involving circular references, conditional types with infer, or branded/template literal types where TypeScript's type inference creates multiple representations of what should be the same type.

Typical symptoms

  • Error message states "Type 'X' is not assignable to type 'X'" with identical type names
  • Error appears in code that should work logically, with no apparent type mismatch
  • Error message includes "two different types with this name exist, but they are unrelated"
  • Error occurs after updating dependencies or adding new packages
  • Compilation fails despite types appearing identical in the code
  • Error appears when using complex conditional types or infer keyword

Common causes

  1. Multiple versions of the same package installed (most common with @babel/types, @types/node, etc.)
  2. Yarn or npm cache contains outdated package versions that conflict with dependency ranges
  3. Circular type references where a type extends or references itself directly or indirectly
  4. Complex conditional types with infer that TypeScript evaluates differently in different contexts
  5. Branded types or template literal types creating multiple incompatible representations
  6. Type aliases with circular dependencies in Record or mapped types
  7. Monorepo workspace with multiple versions of the same dependency

How to fix "Type is not assignable to itself"

1Check for duplicate package versions

First, identify if you have duplicate versions of packages installed. This is the most common cause.

For npm:

bash
npm ls <package-name>
# Example: npm ls @babel/types

For yarn:

bash
yarn why <package-name>
# Example: yarn why @babel/types

For pnpm:

bash
pnpm why <package-name>

Look for multiple version numbers in the output. If you see different versions, proceed to the next steps.

2Use selective version resolution (Yarn)

If you're using Yarn, force all packages to use the same version by adding a resolutions field to your package.json:

json
{
  "resolutions": {
    "@babel/types": "^7.23.0",
    "@types/node": "^20.0.0"
  }
}

Then reinstall dependencies:

bash
rm -rf node_modules yarn.lock
yarn install

Replace the version numbers with the latest compatible version for your project.

3Use overrides (npm 8.3+)

For npm version 8.3 or later, use the overrides field in package.json:

json
{
  "overrides": {
    "@babel/types": "^7.23.0",
    "@types/node": "^20.0.0"
  }
}

Then clean install:

bash
rm -rf node_modules package-lock.json
npm install
4Clear package manager cache

Cached packages can cause version conflicts. Clear your package manager's cache:

For npm:

bash
npm cache clean --force

For yarn:

bash
yarn cache clean

For pnpm:

bash
pnpm store prune

After clearing the cache, reinstall all dependencies:

bash
rm -rf node_modules
npm install  # or yarn install / pnpm install
5Break circular type references

If the error involves circular type references, restructure your types to avoid self-referential inheritance:

Problematic:

typescript
// Don't do this - circular inheritance
interface A extends B {}
interface B extends A {}

// Or this - type alias referencing itself
type Tree = {
  value: string;
  children: Tree[];  // This can work as a property
}
type BadTree = Tree | BadTree[];  // But not in a union

Fixed:

typescript
// Use properties instead of inheritance
interface Node {
  next?: Node;  // Property reference is OK
  value: string;
}

// Or use an interface for recursive structures
interface TreeNode {
  value: string;
  children: TreeNode[];  // Interfaces handle recursion better
}
6Simplify complex conditional types

If the error occurs with conditional types using infer, try simplifying the type logic:

Problematic:

typescript
type Extract<T> = T extends Foo<infer U> ? U : T;

function process<T>(value: T): Extract<T> {
  // Type is not assignable to itself
  return value;
}

Fixed:

typescript
// Add explicit type annotations
function process<T>(value: T): Extract<T> {
  return value as Extract<T>;
}

// Or restructure to avoid conditional in return type
function process<T extends Foo<any>>(value: T): T extends Foo<infer U> ? U : never {
  // ...
}

Alternatively, use a helper type with fewer constraints:

typescript
type Unwrap<T> = T extends Foo<infer U> ? U : never;

function process<T extends Foo<any>>(value: T): Unwrap<T> {
  return value.inner;
}

Advanced notes

Monorepo Considerations: In monorepos using workspaces, this error often occurs when different packages depend on different versions of shared types. Use a root-level package.json with resolutions/overrides to enforce consistent versions across all workspace packages.

TypeScript Version Sensitivity: Some complex type scenarios that trigger this error in older TypeScript versions may be resolved in newer versions. If you're using branded types or template literal types, consider upgrading to TypeScript 5.0+ which has improved type inference.

Branded Types: When using branded types (nominal typing), ensure you're creating new branded values correctly. Mixing branded and unbranded values can trigger this error:

typescript
type UserId = string & { __brand: 'UserId' };

// Wrong - unbrandеd string
const id1: UserId = '123';  // Error

// Correct - properly branded
const id2 = '123' as UserId;

Performance Impact: Deeply nested or highly complex conditional types can cause TypeScript to create multiple type representations during type checking, leading to this error. Simplifying your type definitions can improve both compilation performance and reliability.

pnpm Strict Mode: pnpm's strict dependency resolution can prevent many duplicate version issues that cause this error, but may require explicit configuration of peer dependencies in package.json.

Frequently asked questions

What does "Type is not assignable to itself" mean?
The "Type is not assignable to itself" error is one of TypeScript's most confusing messages because it appears to violate basic logic - how can a type not be compatible with itself? This error occurs when TypeScript's type system determines that what appears to be the same type is actually represented by two different, incompatible type instances. The most common cause is duplicate package installations where different versions of the same package create separate type definitions.
How do I fix "Type is not assignable to itself"?
This error occurs when TypeScript detects that two seemingly identical types are actually incompatible, often due to duplicate package versions, circular type references, or complex conditional type inference issues.
What causes "Type is not assignable to itself"?
Multiple versions of the same package installed (most common with @babel/types, @types/node, etc.) Yarn or npm cache contains outdated package versions that conflict with dependency ranges Circular type references where a type extends or references itself directly or indirectly
Is the "Type is not assignable to itself" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading