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.
is not assignable to parameter of type 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
- Narrow with if checks or ?? defaults
- Validate env vars at startup
- Use the non-null assertion ! only when you’re certain
Detailed fix by platform
Node.js
const port = Number(process.env.PORT ?? 3000);
How to diagnose
- Types — Expected vs actual type
- 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:
Similar errors
- Cannot convert value of type Swift: Cannot convert value of type 'X' to expected argument type 'Y'
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- CASE CASE expression returns mixed types: conversion failed / types cannot be matched
Most viewed in Node.js
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 14 Oct 2026