Skip to content

Commit 739ab63

Browse files
committed
Fix Intl.Collator compare declaration
1 parent f350b52 commit 739ab63

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4419,7 +4419,7 @@ declare namespace Intl {
44194419
}
44204420

44214421
interface Collator {
4422-
compare(x: string, y: string): number;
4422+
readonly compare: (this: void, x: string, y: string) => number;
44234423
resolvedOptions(): ResolvedCollatorOptions;
44244424
}
44254425

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
intlCollatorCompareAccessor.ts(7,7): error TS2322: Type '(this: Intl.Collator, x: string, y: string) => number' is not assignable to type '(this: void, x: string, y: string) => number'.
2+
The 'this' types of each signature are incompatible.
3+
Type 'void' is not assignable to type 'Collator'.
4+
intlCollatorCompareAccessor.ts(11,10): error TS2540: Cannot assign to 'compare' because it is a read-only property.
5+
6+
7+
==== intlCollatorCompareAccessor.ts (2 errors) ====
8+
declare const collator: Intl.Collator;
9+
10+
collator.compare("a", "b");
11+
["a", "b"].sort(collator.compare);
12+
13+
const compare: (this: void, x: string, y: string) => number = collator.compare;
14+
const compareWithThis: Intl.Collator["compare"] = function (this: Intl.Collator, x: string, y: string) {
15+
~~~~~~~~~~~~~~~
16+
!!! error TS2322: Type '(this: Intl.Collator, x: string, y: string) => number' is not assignable to type '(this: void, x: string, y: string) => number'.
17+
!!! error TS2322: The 'this' types of each signature are incompatible.
18+
!!! error TS2322: Type 'void' is not assignable to type 'Collator'.
19+
return 0;
20+
};
21+
22+
collator.compare = (x: string, y: string) => 0;
23+
~~~~~~~
24+
!!! error TS2540: Cannot assign to 'compare' because it is a read-only property.
25+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @noTypesAndSymbols: true
4+
5+
declare const collator: Intl.Collator;
6+
7+
collator.compare("a", "b");
8+
["a", "b"].sort(collator.compare);
9+
10+
const compare: (this: void, x: string, y: string) => number = collator.compare;
11+
const compareWithThis: Intl.Collator["compare"] = function (this: Intl.Collator, x: string, y: string) {
12+
return 0;
13+
};
14+
15+
collator.compare = (x: string, y: string) => 0;

0 commit comments

Comments
 (0)