You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Strange error involving evolving array type and Array#sort callback #31728
TypeScript Version: 3.6.0-dev.20190602 (seems to work with 20190601)
Search Terms:
Code
// @noImplicitAny: trueinterfaceI{a: string;b: string;}declarefunctioncompare(a: I,b: I): number;functiontest(){constresult=[];result.push({foo: true,a: 'a',b: 'b'});// ~~~~~~~~~ error hereresult.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
Activity
ahejlsberg commentedon Jun 6, 2019
This is an effect of #31711 and is fixed by #31802.