Skip to content

Strange error involving evolving array type and Array#sort callback #31728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajafff opened this issue Jun 2, 2019 · 1 comment · Fixed by #31802
Closed

Strange error involving evolving array type and Array#sort callback #31728

ajafff opened this issue Jun 2, 2019 · 1 comment · Fixed by #31802
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Jun 2, 2019

TypeScript Version: 3.6.0-dev.20190602 (seems to work with 20190601)

Search Terms:

Code

// @noImplicitAny: true
interface I {
    a: string;
    b: string;
}

declare function compare(a: I, b: I): number;

function test() {
    const result = [];
    result.push({foo: true, a: 'a', b: 'b'});
    //           ~~~~~~~~~ error here
    result.sort(compare); // commenting out this line makes the error disappear
}

Expected behavior:

No error

Actual behavior:

Argument of type '(a: I, b: I) => number' is not assignable to parameter of type '(a: { foo: boolean; a: string; b: string; }, b: { foo: boolean; a: string; b: string; }) => number'.
  Types of parameters 'a' and 'a' are incompatible.
    Type '{ foo: boolean; a: string; b: string; }' is not assignable to type 'I'.
      Object literal may only specify known properties, and 'foo' does not exist in type 'I'.

Maybe the error makes sense with strictNullChecks enabled (which is off in the above example), but then the location is completely off

Playground Link:

Related Issues:
The only two changes in that version are #31711 and #31687. /cc @ahejlsberg

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 4, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.6.0 milestone Jun 4, 2019
@ahejlsberg
Copy link
Member

This is an effect of #31711 and is fixed by #31802.

@ahejlsberg ahejlsberg added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jun 6, 2019
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants