TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

A value’s type doesn’t match the function parameter — commonly a possibly-undefined value passed where a definite one is required.

Exact message you may see is not assignable to parameter of type
Seen on: Node.js

Meaning

strictNullChecks flags values that may be undefined (env vars, optional props, find() results). Narrow or provide defaults rather than casting.

Common causes

  • process.env values (string | undefined)
  • Optional properties
  • Array.find() results
  • Mismatched object shapes

⚡ Quick fix

  1. Narrow with if checks or ?? defaults
  2. Validate env vars at startup
  3. Use the non-null assertion ! only when you’re certain

Detailed fix by platform

Node.js

  1. const port = Number(process.env.PORT ?? 3000);

How to diagnose

  1. Types — Expected vs actual type
  2. Source — Why can it be undefined?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Cannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …Cannot find module './App.vue' or its corresponding type declarations — TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations. (Vue)Cannot find module '.…CASE — CASE expression returns mixed types: conversion failed / types cannot be matched (SQL)CASEClassCastException — java.lang.ClassCastException: class A cannot be cast to class B (Java)ClassCastExceptiondatatype mismatch — SQLite: datatype mismatch (SQLITE_MISMATCH) (SQL)datatype mismatchE0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308ERR_INVALID_ARG_TYPE — TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined (Node.js)ERR_INVALID_ARG_TYPEERR_UNKNOWN_FILE_EXTENSION — TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" (Node.js)ERR_UNKNOWN_FILE_EXTE…TS2345

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.