← Debugging Guides

阅读中文版本

TypeScript — TS2739: Type is missing properties from type

Fix missing-property errors by constructing complete object literals or reusing helper factories and interfaces.

beginnerdebuggingtypescript

Symptoms

  • error TS2739: Type '{ a: number }' is missing the following properties from type 'User': name, email
  • Object literals fail to satisfy an interface
  • A partial object is passed where a full one is expected
  • Adding a required field to an interface breaks many call sites

Possible causes

  • The object literal omits one or more required properties
  • A recently added required property was not populated at call sites
  • An object typed as a subset is passed where a superset is required
  • Optional markers are missing so fields are treated as required

Diagnosis steps

Read the missing property list

npx tsc --noEmit

Interpretation

The message names exactly which properties are absent, so you can add them or reconsider the type.

Use a factory to build complete objects

const user: User = makeUser({ name })

Interpretation

A factory centralizes required fields so call sites cannot omit them.

Reconsider required versus optional

grep -n "interface User" src/types.ts

Interpretation

If a field is not always available, marking it optional is more honest than forcing every caller to supply it.

Root cause

The object does not provide all required properties of the target type, because the literal is incomplete or the interface requires fields that not every call site can supply.

Fix

Provide all required properties, use a factory or helper to construct complete objects, or mark genuinely optional fields optional so the type reflects reality.

Verify the fix

Rerun the type checker and confirm the error is gone, and run tests to confirm the constructed object has the expected values.

Symptom walkthrough

The compiler reports TS2739 and lists the properties the object is missing relative to the target type. This often follows adding a required field to an interface, which then breaks every call site that builds the object inline. The error is the compiler enforcing the contract, not a defect in the checker.

Fix in practice

Add the missing properties or, better, build objects through a factory that guarantees required fields are present. When a field is not universally available, mark it optional so the type states the truth and callers are not forced to invent values. Prefer this over scattering type assertions.

Verification

Rerun the type checker and confirm the error clears, then run tests to confirm the constructed objects carry the expected values. Passing types plus correct data is the complete fix. A factory that always supplies the required fields keeps the contract enforceable as the type grows.

Diagnostic commands

Check the behavior with commands like these:

npx tsc --noEmit
const user: User = makeUser({ name })
grep -n "interface User" src/types.ts