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.
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
- 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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026