Skip to content

Model Intl.Collator#compare as a readonly bound function property - #64344

Draft
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-intl-collator-compare-method
Draft

Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-intl-collator-compare-method

Conversation

Copilot AI commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Intl.Collator#compare was declared as a method, but per ECMA-402 it is a getter returning a function bound to the collator, with no setter. The method form makes detached usage look receiver-dependent (the cause of typescript-eslint's unbound-method false positive) and permits assignment the platform doesn't allow.

Changes

  • lib.es5.d.ts: compare is now a readonly function-valued property with this: void:

    interface Collator {
        readonly compare: (this: void, x: string, y: string) => number;
        resolvedOptions(): ResolvedCollatorOptions;
    }
  • New compiler test intlCollatorCompare.ts covering call-through, detached call, Array.prototype.sort passthrough, and assignment (now TS2540).

const { compare } = new Intl.Collator("en");
["b", "a"].sort(compare);        // ok, and no longer looks unbound
collator.compare = (x, y) => 0;  // error TS2540: read-only property

No other baselines changed.

@typescript-automation typescript-automation Bot added For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 19, 2026
Copilot AI linked an issue Sep 19, 2026 that may be closed by this pull request
@typescript-automation typescript-automation Bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug and removed For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 19, 2026
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Intl.Collator#compare method type to match spec Model Intl.Collator#compare as a readonly bound function property Sep 19, 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

None yet

Development

Successfully merging this pull request may close these issues.

Intl.Collator#compare method type does not match spec

2 participants