TS2379
TypeScriptERRORNotableTypeHIGH confidence

Argument of type 'X' is not assignable to parameter of type 'X' with 'exactOp...

Production Risk

Build will fail; resolve before shipping.

What this means

A type-checking error (TS2379): Argument of type 'X' is not assignable to parameter of type 'X' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.. This diagnostic is emitted by the TypeScript compiler when argument of type 'X' is not assignable to parameter of type 'X' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties..

Why it happens
  1. 1The value type does not match the declared or expected type
  2. 2A type narrowing or assertion is needed
How to reproduce

TypeScript compiler reports TS2379 during type checking.

trigger — this will error
trigger — this will error
// Triggers TS2379
// Argument of type 'X' is not assignable to parameter of type 'X' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

expected output

error TS2379: Argument of type 'X' is not assignable to parameter of type 'X' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.

Fix

Correct the argument type

WHEN When calling a function with a wrong argument type

Correct the argument type
// Check the function signature and pass the correct type
function fn(x: string) {}
fn(String(value)); // convert if needed

Why this works

The parameter type and the argument type must be compatible.

Sources
Official documentation ↗

TypeScript Compiler Diagnostics

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors