Home/TypeScript Error Codes
Common TypeScript Errors: TS2345, TS2339, TS2304 & How to Fix Them
TypeScript error messages are precise — if you know what each code means, you can fix any error in seconds. This guide covers the six most common error codes with the cause, a broken example, and the correct fix.
TS2345 — Argument Not Assignable to Parameter
Full message: Argument of type 'X' is not assignable to parameter of type 'Y'.
Cause: You are calling a function with a value whose type is not compatible with what the function expects. The types can be completely different, or a union type that is too wide.
Broken code
function greet(name: string) {
return `Hello, ${name}`;
}
const userId: string | number = getUserId(); // could be number
greet(userId); // TS2345: string | number is not assignable to stringFixed code
// Fix 1: Narrow before calling
if (typeof userId === "string") {
greet(userId); // ✓ TypeScript knows it's string here
}
// Fix 2: Convert to string
greet(String(userId)); // ✓
// Fix 3: Widen the parameter
function greet(name: string | number) {
return `Hello, ${name}`;
}
greet(userId); // ✓TS2339 — Property Does Not Exist on Type
Full message: Property 'X' does not exist on type 'Y'.
Cause: The type does not declare the property you are trying to access. Common causes are typos, missing fields in an interface, or accessing a property only present on one branch of a union without narrowing.
Broken code
interface User { id: number; name: string; }
const user: User = { id: 1, name: "Alice" };
console.log(user.email); // TS2339: Property 'email' does not exist on type 'User'
// Also fires on union types without narrowing
type Shape = { kind: "circle"; radius: number } | { kind: "square"; side: number };
function area(s: Shape) {
return s.radius * Math.PI; // TS2339: 'radius' does not exist on type 'Shape'
}Fixed code
// Fix 1: Add the property to the interface
interface User { id: number; name: string; email?: string; }
// Fix 2: Narrow the union type first
function area(s: Shape) {
if (s.kind === "circle") {
return s.radius * Math.PI; // ✓ TypeScript knows it's a circle
}
return s.side ** 2;
}
// Fix 3: Use optional chaining for properties that might not exist
const email = (user as { email?: string }).email ?? "none";TS2304 — Cannot Find Name
Full message: Cannot find name 'X'.
Cause: The identifier is not in scope. Most often caused by a missing import, a missing@types package, or a global not included in the tsconfig lib array.
Broken code
// Missing import
const result = _.groupBy(users, "role"); // TS2304: Cannot find name '_'
// Missing @types package
const el = document.getElementById("app"); // TS2304 if 'DOM' not in tsconfig lib
// Typo
const count = useState(0);
const [n, setN] = useSttate(0); // TS2304: Cannot find name 'useSttate'Fixed code
// Fix 1: Add the import
import _ from "lodash"; // or: npm install --save-dev @types/lodash
// Fix 2: Add 'DOM' to tsconfig lib
{
"compilerOptions": {
"lib": ["ES2020", "DOM"]
}
}
// Fix 3: Fix the typo
const [n, setN] = useState(0); // ✓TS2322 — Type Not Assignable (Variable Assignment)
Full message: Type 'X' is not assignable to type 'Y'.
Cause: Similar to TS2345 but on variable assignment rather than function arguments. The value you are assigning is not compatible with the declared variable type.
Broken code
let status: "active" | "inactive" = "active";
status = "pending"; // TS2322: 'pending' is not assignable to '"active" | "inactive"'
let count: number = "five"; // TS2322: string not assignable to number
// Common with React setState
const [user, setUser] = useState<User>({ id: 1, name: "Alice" });
setUser("Alice"); // TS2322: string not assignable to UserFixed code
// Fix 1: Widen the type to accept the new value
let status: "active" | "inactive" | "pending" = "active";
status = "pending"; // ✓
// Fix 2: Correct the assigned value
let count: number = 5; // ✓
// Fix 3: Pass the correct shape
setUser({ id: 1, name: "Alice" }); // ✓TS2741 — Missing Required Properties
Full message: Property 'X' is missing in type 'Y' but required in type 'Z'.
Cause: You are creating an object literal that does not include all required properties of the target type.
Broken code
interface User {
id: number;
name: string;
email: string;
}
// TS2741: Property 'email' is missing in type '{ id: number; name: string }'
const user: User = { id: 1, name: "Alice" };
// Also common in React — missing required prop
function Avatar({ name, src }: { name: string; src: string }) {
return <img src={src} alt={name} />;
}
<Avatar name="Alice" /> // TS2741: 'src' is missingFixed code
// Fix 1: Provide all required properties
const user: User = { id: 1, name: "Alice", email: "alice@example.com" }; // ✓
// Fix 2: Make the property optional if it may not always be provided
interface User {
id: number;
name: string;
email?: string; // ✓ now optional
}
// Fix 3: Use Partial for partial construction
function createUser(partial: Partial<User>): User {
return { id: Date.now(), name: "Unknown", email: "", ...partial };
}TS2769 — No Overload Matches This Call
Full message: No overload matches this call.
Cause: You called a function that has multiple overload signatures, but your arguments do not satisfy any of them. The error typically lists each overload and why it failed — read those closely.
Broken code
// createElement has overloads for known elements and generic elements
import { createElement } from "react";
// Passing wrong type for known element
createElement("div", { unknownProp: true }); // TS2769: unknownProp is not valid for div
// Common with libraries like Axios
import axios from "axios";
// axios.get expects a string URL as first argument
axios.get(42); // TS2769: number is not assignable to stringFixed code
// Fix: Read the overload error carefully — use the correct types
createElement("div", { className: "container" }); // ✓ className is valid
axios.get("/api/users"); // ✓ string URL
// When the library types are wrong or incomplete:
// Use a type assertion as a last resort
axios.get(42 as unknown as string); // works but loses type safety — prefer the correct fix
// Or look for the correct overload signature:
// Hover over the function in VS Code to see all overloadsFrequently Asked Questions
What causes TypeScript error TS2345?
TS2345 fires when you pass a value whose type is not compatible with what a function expects. Fix by passing the correct type, widening the parameter type, or using a type assertion if you are certain about the value.
What causes TypeScript error TS2339?
TS2339 fires when you access a property not declared on the type. Common causes: typos, accessing a property only on one union branch, or a missing type declaration. Fix by adding the property to the type or using a type guard.
What causes TypeScript error TS2304?
TS2304 fires when TypeScript cannot find an identifier in scope. Common causes: missing import, missing @types package, name only available in a specific lib (like 'document' requires 'DOM' in tsconfig lib), or a typo.
What causes TypeScript error TS2322?
TS2322 fires on variable assignment when the value type is incompatible with the declared variable type. Fix by correcting the value type or widening the variable type to accept the value.
What causes TypeScript error TS2741?
TS2741 fires when an object literal is missing required properties from an interface. Fix by providing all required properties, or mark the missing ones as optional with '?' in the interface definition.
What causes TypeScript error TS2769?
TS2769 fires when calling an overloaded function with arguments that do not match any overload signature. The error lists each failed overload attempt. Fix by providing the correct argument types for the intended overload.
Convert JavaScript to TypeScript automatically
Paste your JavaScript and get properly annotated TypeScript back instantly — fewer errors from day one.
Convert now →From the blog
View all →
May 13, 2026
Convert XML to JSON Online: Complete Guide for Developers (2026)

May 11, 2026
Convert CSV to JSON Online Free (Best Developer Guide 2026)

May 6, 2026
Convert YAML to JSON Online Free (2026 Developer Guide)

Apr 30, 2026
Convert JSON to Zod Schema Online (2026) – Free Tool & Complete Guide

Apr 30, 2026
Top 50 JavaScript to TypeScript Converters (2026) – Free, AI & Online Tools