Skip to content

Improve type ordering #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged

Improve type ordering #1284

merged 2 commits into from
Jun 24, 2025

Conversation

ahejlsberg
Copy link
Member

Implements what I discuss here.

Fixes #1278.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Updates the internal type flag ordering for complexity and adjusts compiler error baselines to match the new union type representation.

  • Reorders TypeFlags bit positions so that more complex types (indexed access, conditional) sort later
  • Updates compiler error baselines in testdata to reflect the new string representation order
  • Adds a descriptive comment explaining the importance of numeric ordering in CompareTypes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
testdata/baselines/reference/submodule/compiler/awaitedTypeNoLib.errors.txt.diff Adjusted expected error output to swap the order of the union type representation
testdata/baselines/reference/submodule/compiler/awaitedTypeNoLib.errors.txt Synchronized the baseline error file with updated union ordering
internal/checker/types.go Moved IndexedAccess and Conditional flags to higher bits, added comment explaining type ordering
Comments suppressed due to low confidence (1)

internal/checker/types.go:411

  • Consider adding unit tests for CompareTypes to verify that TypeFlags ordering (TemplateLiteral, StringMapping, IndexedAccess, Conditional) correctly influences type sorting, preventing regressions in type complexity ordering.
// Note that for types of different kinds, the numeric values of TypeFlags determine the order

@ahejlsberg ahejlsberg added this pull request to the merge queue Jun 24, 2025
Merged via the queue into main with commit 5a79b0c Jun 24, 2025
22 checks passed
@ahejlsberg ahejlsberg deleted the fix-type-ordering branch June 24, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type Instantiation is Excessively Deep Error only on TS-Go
3 participants