Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4419,7 +4419,7 @@ declare namespace Intl {
}

interface Collator {
compare(x: string, y: string): number;
readonly compare: (this: void, x: string, y: string) => number;
resolvedOptions(): ResolvedCollatorOptions;
}

Expand Down
25 changes: 25 additions & 0 deletions tests/baselines/reference/intlCollatorCompareAccessor.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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'.
The 'this' types of each signature are incompatible.
Type 'void' is not assignable to type 'Collator'.
intlCollatorCompareAccessor.ts(11,10): error TS2540: Cannot assign to 'compare' because it is a read-only property.


==== intlCollatorCompareAccessor.ts (2 errors) ====
declare const collator: Intl.Collator;

collator.compare("a", "b");
["a", "b"].sort(collator.compare);

const compare: (this: void, x: string, y: string) => number = collator.compare;
const compareWithThis: Intl.Collator["compare"] = function (this: Intl.Collator, x: string, y: string) {
~~~~~~~~~~~~~~~
!!! error TS2322: Type '(this: Intl.Collator, x: string, y: string) => number' is not assignable to type '(this: void, x: string, y: string) => number'.
!!! error TS2322: The 'this' types of each signature are incompatible.
!!! error TS2322: Type 'void' is not assignable to type 'Collator'.
return 0;
};

collator.compare = (x: string, y: string) => 0;
~~~~~~~
!!! error TS2540: Cannot assign to 'compare' because it is a read-only property.

15 changes: 15 additions & 0 deletions tests/cases/compiler/intlCollatorCompareAccessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @strict: true
// @noEmit: true
// @noTypesAndSymbols: true

declare const collator: Intl.Collator;

collator.compare("a", "b");
["a", "b"].sort(collator.compare);

const compare: (this: void, x: string, y: string) => number = collator.compare;
const compareWithThis: Intl.Collator["compare"] = function (this: Intl.Collator, x: string, y: string) {
return 0;
};

collator.compare = (x: string, y: string) => 0;
Loading