Microsoft/TypeScript

Intl.Collator#compare method type does not match spec

Open

#62 048 ouverte le 11 juil. 2025

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: lib.d.tsHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

⚙ Compilation target

ES2022

⚙ Library

N/A

Missing / Incorrect Definition

The Intl.Collator object has a compare method which is declared as compare(x: string, y: string): number; but according to the relevant spec is actually get compare(): (this: void, x: string, y: string) => number. Importantly, the spec states that

The returned function is bound to collator so that it can be passed directly to Array.prototype.sort or other functions

Sample Code

I'm having trouble putting together a Playground example that cares about the difference (which is admittedly subtle!) but it's the cause of https://github.com/typescript-eslint/typescript-eslint/issues/7098

Documentation Link

Collator#compare spec MDN docs on compare method

Guide contributeur