TypeScript Compiler Errors Reference: Fix TS2322, TS2345, TS7053, TS2532, and More
compiler-errorsdiagnosticsdebuggingstrict-modetype-inferencereference

TypeScript Compiler Errors Reference: Fix TS2322, TS2345, TS7053, TS2532, and More

TTypeScript Toolbox Editorial Team
2026-11-20
7 min read

A practical TypeScript compiler errors reference for diagnosing TS2322, TS2345, TS7053, TS2532, TS2741, TS2551, and TS18046 safely.

TypeScript compiler errors are usually precise clues about a mismatch in your code, not obstacles to bypass. This reference explains what recurring diagnostics such as TS2322, TS2345, TS2551, TS2532, TS2741, TS7053, and TS18046 mean, shows minimal fixes, and provides a reusable checklist for deciding when to change a value, narrow a type, improve an object shape, or revise a declaration.

Overview

The safest way to fix TypeScript errors is to understand the relationship the compiler is checking. Most diagnostics fall into a few groups:

  • Assignment: a value is not compatible with the type of a variable, property, or return value.
  • Arguments: a function call receives a value that does not match its parameter type.
  • Object shapes: a required property is missing, or a property name is incorrect.
  • Nullability: a value may be undefined or null when code assumes it exists.
  • Indexing: a string or number is used to access an object without proving that the key is valid.
  • Unknown data: a value from a catch clause, API, or external package cannot safely be used before it is narrowed.

Read the complete diagnostic before changing code. The line TypeScript highlights is often where the mismatch becomes visible, but the underlying cause may be earlier: a widened variable, an optional property, an incomplete generic constraint, or an inaccurate third-party declaration. Error wording can also vary with TypeScript versions and compiler options, so use the diagnostic code as the stable starting point.

ErrorTypical meaningUsually safe first step
TS2322A value cannot be assigned to the expected type.Correct the value or make the declared type reflect the real domain.
TS2345An argument is not assignable to a function parameter.Inspect the parameter type and the value at the call site.
TS2551A property or method name does not exist, often with a suggested spelling.Check the spelling, object type, and intended API.
TS2532An object is possibly undefined.Narrow, provide a fallback, or model the value as required.
TS2741A required property is missing from an object.Add the property or mark it optional only when that is semantically correct.
TS7053A value cannot safely index an object with the supplied key.Use keyof, a key map, or an explicit index signature.
TS18046A value, commonly an error in a catch block, has type unknown.Narrow it with a type guard before reading properties.

Checklist by scenario

When you see TS2322: assignment is incompatible

TS2322 appears when the type on the right cannot be assigned to the type on the left. For example:

let count: number = '3';

The safe fix is to decide what the value should be. Convert validated input to a number, or change the declaration if the value is genuinely text:

const count = Number(input);
if (Number.isNaN(count)) {
  throw new Error('Count must be numeric');
}

Do not solve an assignment error with as number unless you have already established that the runtime value is a number. A type assertion changes the compiler's view; it does not convert or validate the value.

When you see TS2345: an argument is not assignable

TS2345 is the function-call version of a type mismatch:

function sendEmail(address: string) {
  // ...
}

sendEmail(undefined);

Trace the value back to its source. If it comes from an optional property, narrow it before the call:

type User = { email?: string };

function notify(user: User) {
  if (user.email) {
    sendEmail(user.email);
  }
}

If the function is expected to accept an absent address, change its contract deliberately and handle that case inside the function. Avoid making parameters optional simply to silence an error.

When you see TS2551 or TS2741: object shape problems

TS2551 commonly indicates a misspelled property or a mismatch between the object you have and the API you intended to use:

const profile = { displayName: 'Ari' };
console.log(profile.displayname);

Check spelling and capitalization first. Then confirm that the variable has the type you think it has, especially when a dependency has changed its declarations.

TS2741 means a required property is missing:

type Config = {
  host: string;
  port: number;
};

const config: Config = { host: 'localhost' };

Add port if every valid configuration needs one. Use an optional property only if absence is a supported state, and provide a default at the boundary where configuration enters the application.

When you see TS2532: a value may be undefined

Strict null checking treats optional values honestly. This code is unsafe:

const first = users[0];
console.log(first.name);

Narrow the value, use optional chaining when no action is needed for absence, or provide a meaningful fallback:

const first = users[0];
if (first) {
  console.log(first.name);
}

const label = first?.name ?? 'No user';

An expression such as users[0]! is appropriate only when a preceding invariant guarantees a non-empty array. Otherwise, it hides a possible runtime failure.

When you see TS7053: unsafe dynamic indexing

TypeScript cannot assume that an arbitrary string is a property of a specific object:

const labels = { open: 'Open', closed: 'Closed' };
const state: string = getState();
const label = labels[state];

If the valid keys are known, model them explicitly:

type State = keyof typeof labels;

function getLabel(state: State) {
  return labels[state];
}

If keys are open-ended, use an index signature or a Record with a deliberate value type. Do not add as keyof typeof labels at every call site unless the input has been validated.

When you see TS18046: a value is unknown

Values typed as unknown require proof before property access. This is especially common when handling errors:

try {
  await request();
} catch (error) {
  if (error instanceof Error) {
    console.error(error.message);
  } else {
    console.error('Unexpected failure', error);
  }
}

This pattern is safer than assuming every thrown value is an Error. For API responses and parsed JSON, use a runtime validation step before treating the data as an application type. Static TypeScript types do not validate external input at runtime.

What to double-check

  • Inference: hover over the value and the receiving expression in your editor. The inferred type may be narrower or wider than expected.
  • Nullability: inspect optional properties, array lookups, DOM queries, and functions that can return no result.
  • Object shape: compare required and optional properties, readonly modifiers, literal values, and nested types.
  • Generics: verify that a type parameter has the constraint required by the operation. A generic function may need extends or a more precise return type.
  • Control-flow narrowing: make sure the check occurs in the same reachable path where the value is used. Assignments or callbacks can change what TypeScript can prove.
  • Third-party declarations: check the package's exported types and version before overriding them. If the declarations are wrong, prefer a focused declaration correction over scattered assertions.
  • Compiler configuration: compare local and CI tsconfig files. Options such as strictNullChecks, noImplicitAny, and noUncheckedIndexedAccess affect diagnostics.

For a broader strictness rollout, use the TypeScript Strict Mode Rollout checklist. If the issue concerns a JavaScript dependency without reliable types, the guide to writing TypeScript declaration files provides a more maintainable path.

Common mistakes

  1. Using assertions as conversions. value as string does not turn a number, null, or unknown value into a string.
  2. Making everything optional. Optional properties spread uncertainty through the application. Keep required fields required when the domain requires them.
  3. Using a broad index signature to silence TS7053. Record<string, unknown> may be appropriate for dictionary data, but it can conceal misspelled fixed keys.
  4. Fixing the receiving type instead of the source. Widening a variable to any removes useful feedback and usually moves the failure to runtime.
  5. Ignoring the first error. One incorrect generic, missing property, or failed narrowing can produce many downstream diagnostics. Fix the earliest meaningful error and compile again.
  6. Trusting generated or external data without validation. An interface describes expected data; it does not check JSON, environment variables, form input, or API responses.

When an assertion is genuinely necessary at a trusted boundary, keep it narrow, document the invariant, and consider a runtime check nearby. For reusable type patterns, the TypeScript Utility Types Cookbook can help you avoid duplicating incompatible object shapes.

When to revisit

Return to this reference whenever a dependency upgrade changes an inferred type, a TypeScript upgrade reports new diagnostics, strictness options are enabled, or a CI build fails while local editor feedback appears different. Also revisit the relevant boundary when an API response, configuration format, form model, or shared package changes.

Use this short triage routine:

  1. Copy the complete diagnostic, including the expected and received types.
  2. Reduce the failing expression to the smallest reproducible example.
  3. Inspect the inferred types at the source and destination.
  4. Classify the problem as assignment, argument, shape, nullability, indexing, generic inference, or unknown data.
  5. Apply the narrowest semantic fix: validate, narrow, correct the shape, constrain the generic, or update the declaration.
  6. Run the compiler and relevant tests again, then remove temporary assertions and debugging types.

Keep the project's compiler command and configuration visible to contributors so errors can be reproduced consistently. Pair this reference with the TypeScript ESLint rules reference for feedback that catches related issues during review, and with the TypeScript testing guide when a type fix changes runtime behavior.

Related Topics

#compiler-errors#diagnostics#debugging#strict-mode#type-inference#reference
T

TypeScript Toolbox Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.