Microsoft/TypeScript

Intl.Collator#compare method type does not match spec

开放

#62,048 创建于 2025年7月11日

 (4 条评论) (0 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: lib.d.tsHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

⚙ 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

贡献者指南