Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
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 2 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;
compare(this: void, x: string, y: string): number;
resolvedOptions(): ResolvedCollatorOptions;
}

Expand Down
44 changes: 44 additions & 0 deletions 44 tests/baselines/reference/collatorCompareBoundFunction.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'CallableFunction'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'NewableFunction'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.
collatorCompareBoundFunction.ts(1,27): error TS2339: Property 'Collator' does not exist on type 'typeof Intl'.
collatorCompareBoundFunction.ts(14,32): error TS2339: Property 'sort' does not exist on type '{}'.


!!! error TS2318: Cannot find global type 'Array'.
!!! error TS2318: Cannot find global type 'Boolean'.
!!! error TS2318: Cannot find global type 'CallableFunction'.
!!! error TS2318: Cannot find global type 'Function'.
!!! error TS2318: Cannot find global type 'IArguments'.
!!! error TS2318: Cannot find global type 'NewableFunction'.
!!! error TS2318: Cannot find global type 'Number'.
!!! error TS2318: Cannot find global type 'Object'.
!!! error TS2318: Cannot find global type 'RegExp'.
!!! error TS2318: Cannot find global type 'String'.
==== collatorCompareBoundFunction.ts (2 errors) ====
const collator = new Intl.Collator();
~~~~~~~~
!!! error TS2339: Property 'Collator' does not exist on type 'typeof Intl'.

// Should be usable as a function with no dynamic `this`
const cmp: (a: string, b: string) => number = collator.compare;

// Function expecting a `this: void` bound compare function
function useCompare(fn: (this: void, a: string, b: string) => number): number {
return fn("a", "b");
}

useCompare(collator.compare);

// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);
~~~~
!!! error TS2339: Property 'sort' does not exist on type '{}'.

31 changes: 31 additions & 0 deletions 31 tests/baselines/reference/collatorCompareBoundFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//// [tests/cases/conformance/intl/collatorCompareBoundFunction.ts] ////

//// [collatorCompareBoundFunction.ts]
const collator = new Intl.Collator();

// Should be usable as a function with no dynamic `this`
const cmp: (a: string, b: string) => number = collator.compare;

// Function expecting a `this: void` bound compare function
function useCompare(fn: (this: void, a: string, b: string) => number): number {
return fn("a", "b");
}

useCompare(collator.compare);

// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);


//// [collatorCompareBoundFunction.js]
"use strict";
const collator = new Intl.Collator();
// Should be usable as a function with no dynamic `this`
const cmp = collator.compare;
// Function expecting a `this: void` bound compare function
function useCompare(fn) {
return fn("a", "b");
}
useCompare(collator.compare);
// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);
35 changes: 35 additions & 0 deletions 35 tests/baselines/reference/collatorCompareBoundFunction.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [tests/cases/conformance/intl/collatorCompareBoundFunction.ts] ////

=== collatorCompareBoundFunction.ts ===
const collator = new Intl.Collator();
>collator : Symbol(collator, Decl(collatorCompareBoundFunction.ts, 0, 5))
>Intl : Symbol(Intl, Decl(lib.es2022.intl.d.ts, --, --))

// Should be usable as a function with no dynamic `this`
const cmp: (a: string, b: string) => number = collator.compare;
>cmp : Symbol(cmp, Decl(collatorCompareBoundFunction.ts, 3, 5))
>a : Symbol(a, Decl(collatorCompareBoundFunction.ts, 3, 12))
>b : Symbol(b, Decl(collatorCompareBoundFunction.ts, 3, 22))
>collator : Symbol(collator, Decl(collatorCompareBoundFunction.ts, 0, 5))

// Function expecting a `this: void` bound compare function
function useCompare(fn: (this: void, a: string, b: string) => number): number {
>useCompare : Symbol(useCompare, Decl(collatorCompareBoundFunction.ts, 3, 63))
>fn : Symbol(fn, Decl(collatorCompareBoundFunction.ts, 6, 20))
>this : Symbol(this, Decl(collatorCompareBoundFunction.ts, 6, 25))
>a : Symbol(a, Decl(collatorCompareBoundFunction.ts, 6, 36))
>b : Symbol(b, Decl(collatorCompareBoundFunction.ts, 6, 47))

return fn("a", "b");
>fn : Symbol(fn, Decl(collatorCompareBoundFunction.ts, 6, 20))
}

useCompare(collator.compare);
>useCompare : Symbol(useCompare, Decl(collatorCompareBoundFunction.ts, 3, 63))
>collator : Symbol(collator, Decl(collatorCompareBoundFunction.ts, 0, 5))

// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);
>sorted : Symbol(sorted, Decl(collatorCompareBoundFunction.ts, 13, 5))
>collator : Symbol(collator, Decl(collatorCompareBoundFunction.ts, 0, 5))

91 changes: 91 additions & 0 deletions 91 tests/baselines/reference/collatorCompareBoundFunction.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//// [tests/cases/conformance/intl/collatorCompareBoundFunction.ts] ////

=== collatorCompareBoundFunction.ts ===
const collator = new Intl.Collator();
>collator : any
> : ^^^
>new Intl.Collator() : any
> : ^^^
>Intl.Collator : any
> : ^^^
>Intl : typeof Intl
> : ^^^^^^^^^^^
>Collator : any
> : ^^^

// Should be usable as a function with no dynamic `this`
const cmp: (a: string, b: string) => number = collator.compare;
>cmp : (a: string, b: string) => number
> : ^ ^^ ^^ ^^ ^^^^^
>a : string
> : ^^^^^^
>b : string
> : ^^^^^^
>collator.compare : any
> : ^^^
>collator : any
> : ^^^
>compare : any
> : ^^^

// Function expecting a `this: void` bound compare function
function useCompare(fn: (this: void, a: string, b: string) => number): number {
>useCompare : (fn: (this: void, a: string, b: string) => number) => number
> : ^ ^^ ^^^^^
>fn : (this: void, a: string, b: string) => number
> : ^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>this : void
> : ^^^^
>a : string
> : ^^^^^^
>b : string
> : ^^^^^^

return fn("a", "b");
>fn("a", "b") : number
> : ^^^^^^
>fn : (this: void, a: string, b: string) => number
> : ^ ^^ ^^ ^^ ^^ ^^ ^^^^^
>"a" : "a"
> : ^^^
>"b" : "b"
> : ^^^
}

useCompare(collator.compare);
>useCompare(collator.compare) : number
> : ^^^^^^
>useCompare : (fn: (this: void, a: string, b: string) => number) => number
> : ^ ^^ ^^^^^
>collator.compare : any
> : ^^^
>collator : any
> : ^^^
>compare : any
> : ^^^

// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);
>sorted : any
> : ^^^
>["z", "ä", "a"].sort(collator.compare) : any
> : ^^^
>["z", "ä", "a"].sort : any
> : ^^^
>["z", "ä", "a"] : {}
> : ^^
>"z" : "z"
> : ^^^
>"ä" : "ä"
> : ^^^
>"a" : "a"
> : ^^^
>sort : any
> : ^^^
>collator.compare : any
> : ^^^
>collator : any
> : ^^^
>compare : any
> : ^^^

18 changes: 18 additions & 0 deletions 18 tests/cases/conformance/intl/collatorCompareBoundFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @target: es2022
// @lib: es2022.intl
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es2022.intl doesn't reference lib.es5, so Collator isn't actually defined in your test script (check the baselines).

Either change this to

Suggested change
// @target: es2022
// @lib: es2022.intl
// @target: es5
// @lib: es5

or just get rid of the lib option entirely, and use the default.

// @strict: true

const collator = new Intl.Collator();

// Should be usable as a function with no dynamic `this`
const cmp: (a: string, b: string) => number = collator.compare;

// Function expecting a `this: void` bound compare function
function useCompare(fn: (this: void, a: string, b: string) => number): number {
return fn("a", "b");
}

useCompare(collator.compare);

// Should work with Array.prototype.sort
const sorted = ["z", "ä", "a"].sort(collator.compare);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.