microsoft / microsoft/TypeScript

Inference from result of generic function no longer produces a union

Open
#63,227 1 comment 0 reactions 1 assignee View on GitHub

@ahejlsberg is already working on this.

Since Mar 11, 2026.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

function inference

🕗 Version & Regression Information
  • This changed between versions 5.9 and 6.0-rc
⏯ Playground Link

Playground Link

💻 Code

declare function deepEqual<T>(actualValue: T, expectedValue: T, message?: string): void;
declare function compact<T>(obj: T): T 
// Error
deepEqual(compact({ a: "hello", b: undefined }), {
    a: "hello",
});
// Ok
deepEqual({ a: "hello", b: undefined }, {
    a: "hello",
});
🙁 Actual behavior

First call fails. T for deepEqaul is inferred to { a: string, b: undefined;} instead of { a: string; b: undefined; } | { a: string; b?: undefined; } as it is for the second call that succeeds. In 5.9, T is inferred to { a: string; } which is not really great either.

🙂 Expected behavior

Both calls should pass type checking

Additional information about the issue

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.