Loading...
Loading...
Type 'string' is not assignable to type 'number'TypeScript's type checker found that you're trying to assign a value of one type to a variable or parameter that expects a different type. This is TypeScript's core feature — catching type mismatches at compile time before they become runtime bugs.
Convert the value to the correct type.
// ❌ Type error — string not assignable to number
const age: number = "25"; // 💥
// ✅ Convert to number
const age: number = parseInt("25", 10);
const age: number = Number("25");If the type annotation is wrong, update it to match the actual value.
// ❌ Wrong annotation
const name: number = "Alice"; // 💥
// ✅ Correct annotation
const name: string = "Alice";If the value can be multiple types, use a union type.
// ✅ Accept both string and number
function display(value: string | number) {
console.log(value.toString());
}