TypeScript Basics Errors
50 errors
Common typescript basics errors and how to fix them.
50 / 50
- 1
Type 'string' is not assignable to type 'number'
You tried to assign a value of one type to a variable or parameter of a different, incompatible type. TypeScript caught the mismatch at compile time.
- 2
Property 'X' does not exist on type 'Y'
You tried to access a property that TypeScript doesn't know about on the given type. The property is not declared in the interface or type.
- 3
Cannot find name 'X'
You referenced a name (variable, function, or type) that TypeScript cannot find in the current scope or imports.
- 4
Expected 0 arguments, but got 1
You called a function with more or fewer arguments than its signature declares. TypeScript checks argument counts at compile time.
- 5
Object is possibly 'null' or 'undefined'
With strictNullChecks enabled, TypeScript prevents you from accessing properties on values that could be null or undefined without checking first.
- 6
Property 'X' is missing in type 'Y'
You assigned an object to a typed variable, but the object is missing one or more required properties declared in the interface.
- 7
Argument of type 'X' is not assignable to parameter of type 'Y'
You passed a value to a function, but the value's type doesn't match the function's parameter type.
- 8
'X' only refers to a type, but is being used as a value here
You used a type or interface name in a value position (e.g., with `new` or as a variable), but types are erased at compile time and have no runtime existence.
- 9
No overload matches this call
You called a function with arguments that don't match any of its declared overload signatures. TypeScript checks each overload in order.
- 10
Variable 'X' implicitly has an 'any' type
With noImplicitAny enabled, TypeScript errors when a variable or parameter has no type annotation and its type cannot be inferred, defaulting to any.
- 11
Cannot assign to 'X' because it is a read-only property
You tried to assign a new value to a property marked as readonly, or to a Readonly<T> object. TypeScript prevents mutations of readonly properties at compile time.
- 12
Generic type requires 1 type argument(s)
You used a generic type or function without providing the required type parameter(s). TypeScript requires explicit type arguments when they cannot be inferred.
- 13
Type 'X' is not comparable to type 'Y'
You compared two values whose types have no overlap — the comparison will always be false or true. TypeScript flags this as a likely logic error.
- 14
Duplicate identifier 'X'
You declared two variables, functions, types, or interfaces with the same name in the same scope. TypeScript does not allow duplicate identifiers (except for interface merging).
- 15
'await' is only allowed in async functions
You used the `await` keyword outside of an async function or at the top level without top-level await support. await requires an async context.
- 16
Module has no exported member 'X'
You tried to import a name from a module, but the module doesn't export anything with that name. The import doesn't match any export.
- 17
Type 'X' has no properties in common with type 'Y'
You assigned or compared two object types that have no properties in common. This is usually a sign of using the wrong type.
- 18
Unable to resolve signature of target constructor
TypeScript couldn't determine which overload or signature to use for a function or constructor call, often due to complex generic types.
- 19
Excessive stack depth comparing types
TypeScript's type checker exceeded its recursion limit while comparing two types. This usually happens with deeply recursive or self-referential types.
- 20
'this' implicitly has type 'any'
With noImplicitThis enabled, TypeScript errors when `this` is used in a function without a determined type. This commonly happens in standalone functions.
- 21
TS2783: 'X' is specified more than once
You have a property in both a spread object and an explicit assignment. The explicit value wins, which may not be intended.
- 22
TS4114: This member must have an 'override' modifier
You are overriding a base class method but forgot the 'override' keyword. This is required when noImplicitOverride is enabled.
- 23
TS4116: Type is not included in the union
Your switch case value doesn't match any union member's discriminant property value.
- 24
TS4124: This member cannot have an 'override' modifier
You marked a method with 'override' but the base class doesn't have a method with that name.
- 25
TS4125: 'override' modifier cannot be used with 'declare'
You cannot use both 'override' and 'declare' on the same class member.
- 26
TS4138: Rest element must be last in tuple type
In a tuple type, the rest element (...) can only appear as the last element.
- 27
TS4144: Indexed type must have a type annotation
There's an issue with the computed property or mapped type key. The key type needs to be properly constrained.
- 28
TS4222: No overload expects N arguments
You're calling a function with a number of arguments that doesn't match any overload signature.
- 29
TS4232: This expression is not callable
You're trying to invoke something as a function, but TypeScript sees it as a non-function type.
- 30
TS4242: Enum member must have initializer
An enum member needs a value but doesn't have one, and TypeScript can't infer it.
- 31
Wrong type assertion hides runtime error
You used 'as Type' to override the inferred type — TypeScript stops checking, and the wrong type causes a runtime error.
- 32
Enum reverse mapping surprise
You iterated over a numeric enum and got both keys and values — TypeScript creates reverse mappings for numeric enums.
- 33
Generic type inference produces unexpected type
Your generic function's type parameter was inferred as a wider type than intended — the resulting type is too permissive.
- 34
Decorator metadata not emitted
You used a decorator that relies on metadata reflection, but the compiler option is not enabled — metadata is missing at runtime.
- 35
Symbol unique type collision
You compared two Symbols with the same description but they are different unique symbols — Symbol() always creates a unique identity.
- 36
Mixin type conflict at runtime
Two mixins define the same method — the last applied mixin wins, and earlier methods are silently lost at runtime.
- 37
Conditional type distribution unexpected result
Your conditional type is distributive over a union — it evaluates separately for each member, producing a union of results.
- 38
strictNullChecks: possibly null value
Your variable has type T | null but you used it as if it were T — TypeScript blocks this under strict null checks.
- 39
noImplicitAny: parameter implicitly has any
Your function parameter has no type annotation — TypeScript infers 'any' and reports an error when noImplicitAny is enabled.
- 40
strictFunctionTypes: incompatible function signature
You assigned a function to a type that expects a different parameter variance — strictFunctionTypes catches the mismatch.
- 41
Index signature missing for dynamic property access
You used obj[dynamicKey] but the type of obj has no index signature — TypeScript cannot guarantee the key exists.
- 42
Discriminated union exhaustiveness check fails
Your switch statement is missing a case for a union member — the exhaustiveness check via 'default: assertNever' catches it.
- 43
Generic constraint violation: type does not satisfy extends
You passed a type that does not satisfy the 'extends' constraint of the generic parameter — TypeScript rejects it.
- 44
Structural typing allows unexpected assignment
An object with extra properties was assigned to a type with fewer properties — structural typing allows it, but it may hide a bug.
- 45
Excess property check only on object literals
You assigned a variable with extra properties to a type — TypeScript does not check excess properties from variables, only from literals.
- 46
Type narrowing lost after assignment
You narrowed a type in an if block, but after assigning to a variable, the narrowing is lost — the variable has the wide type.
- 47
const assertion vs let: mutable vs readonly
You used 'let x = { a: 1 } as const' expecting immutability, but 'let' allows reassignment — only 'const' prevents it.
- 48
Promise type unwrapping confusion
Your async function returns Promise<T> but TypeScript infers Promise<Promise<T>> — async already wraps the return in a Promise.
- 49
Readonly violation: mutating a readonly property
You tried to push to a readonly array or assign to a readonly property — TypeScript blocks mutations of readonly types.
- 50
Branded type confusion: intersection with phantom property
You used a branded type (string & { __brand: 'X' }) but did not properly construct the brand — the phantom property does not exist at runtime.
No errors found.