Skip to content

Fix reverse mapped type inference when all properties are context-sensitive - #64252

Open
Devansh Jethmalani (devanshj) wants to merge 3 commits into
microsoft:mainfrom
devanshj:issue-64251-all-properties-context-sensitive
Open

Fix reverse mapped type inference when all properties are context-sensitive#64252
Devansh Jethmalani (devanshj) wants to merge 3 commits into
microsoft:mainfrom
devanshj:issue-64251-all-properties-context-sensitive

Conversation

@devanshj

@devanshj Devansh Jethmalani (devanshj) commented Sep 12, 2026

Copy link
Copy Markdown

Fixes #64251

The code change feels wrong because there should be a reason why the original code was like that but given there are no tests failing (well there's one baseline change but it doesn't look like a bad change to me) so I thought of opening this PR.

Happy to be proven wrong by showing some counter bad changes. Maybe I can be a little more conservative and target only the linked issue case.

Copilot AI balanced review requested due to automatic review settings September 12, 2026 13:24
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 12, 2026
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The unresolved inference issue prevents correctly inferring the generic context member.

Pull request overview

Fixes reverse-mapped type inference when all properties are context-sensitive.

Changes:

  • Broadens partial inferability for non-empty object literals.
  • Adds regression coverage and compiler baselines.
  • Updates existing inference expectations.

The callback is contextually typed, but the generic D["context"] remains inferred as object rather than { foo: number }.

File summaries
File Summary
tsc/testdata/tests/cases/compiler/reverseMappedTypeWithAllContextSensitiveProperties.ts Adds regression coverage.
tsc/testdata/baselines/reference/compiler/reverseMappedTypeWithAllContextSensitiveProperties.types Records inferred types.
tsc/testdata/baselines/reference/compiler/reverseMappedTypeWithAllContextSensitiveProperties.symbols Records symbol mappings.
tsc/testdata/baselines/reference/compiler/reverseMappedPartiallyInferableTypes.types Updates inference expectations.
tsc/internal/checker/inference.go Adjusts reverse-mapped type inferability; generic context inference remains incomplete.
Review details

Suppressed comments (1)

tsc/internal/checker/inference.go:1060

  • This change only makes the callback contextually typed; it does not make the generic D infer its context member. The generated .types baseline for this test still reports the call result as { context: object; ... }, so a consumer of const machine = createMachine(...) cannot access machine.context.foo even though the callback parameter can. Please add a return-type assertion to the regression test and adjust the inference path so D["context"] is inferred as { foo: number }, not just used to contextualize entry.
	return t.objectFlags&ObjectFlagsNonInferrableType == 0 || isObjectLiteralType(t) && len(c.getPropertiesOfType(t)) != 0 || isTupleType(t) && core.Some(c.getElementTypes(t), c.isPartiallyInferableType)
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@devanshj

Copy link
Copy Markdown
Author

a consumer of const machine = createMachine(...) cannot access machine.context.foo

nice catch copilot fixed it! (just needed to tweak the userland types, the compiler is already good)

@devanshj Devansh Jethmalani (devanshj) changed the title fix reverse mapped type inference when all properties are context-sensitive Fix reverse mapped type inference when all properties are context-sensitive Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Object with all context-sensitive properties requires at least one non-context-sensitive property for inference to work

2 participants