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
I see a difference between how TypeScript 1.5 and 1.6 infer the type of function call. I am not sure if this is a bug. I would like to understand if this an indication of something subtle that users of the compiler must know. The shell output that follows illustrates how to reproduce this issue.
These are the two versions of the compiler that I am working with.
$ ./1.5.3/node_modules/.bin/tsc --version
message TS6029: Version 1.5.3
$ ./1.6.2/node_modules/.bin/tsc --version
message TS6029: Version 1.6.2
$ cat hello.ts
/**
* A few lines copied from the JQuery type definition to illustrate this
* bug.
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1ba21f73e4104d567d64c03c89604e5960ae7f93/jquery/jquery.d.ts#L1547
*/
interface JQuery {
// 1
data(key: string, value: any): JQuery;
// 2
data(obj: { [key: string]: any; }): JQuery;
// 3
data(key: string): any;
// 4
data(): any;
};
function caller(jq: JQuery) {
// We expect the data call below to call version 3 of the data function
// mentioned above.
var s: string = jq.data("hello");
}
TypeScript 1.5.3 and 1.6.2 compile the above file differently. 1.6.2 reports a compile error.
$ ./1.5.3/node_modules/.bin/tsc hello.ts # No error here
$ ./1.6.2/node_modules/.bin/tsc hello.ts
hello.ts(20,9): error TS2322: Type 'JQuery' is not assignable to type 'string'.
$ cat hello2.ts
/**
* A few lines copied from the JQuery type definition to illustrate this
* bug.
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1d6c126e8ead25892ded5a32df2e813ffad06905/jquery/jquery.d.ts#L1547
*/
interface JQuery {
// 1
data(key: string, value: any): JQuery;
// 3
data(key: string): any;
// 2
data(obj: { [key: string]: any; }): JQuery;
// 4
data(): any;
};
function caller(jq: JQuery) {
// We expect the data call below to call version 3 of the data function
// mentioned above.
var s: string = jq.data("hello");
}
Both compiler versions 1.5.3 and 1.6.2 don't report any error when compiling hello2.ts.
$ ./1.5.3/node_modules/.bin/tsc hello2.ts # No error
$ ./1.6.2/node_modules/.bin/tsc hello2.ts # No error
Is the difference in behavior between 1.5.3 and 1.6.2 a regression or an improvement? Why did Definitely Typed's file change the order of the definition of these functions? I could not figure this out fro m the commit message that made the change.
The text was updated successfully, but these errors were encountered:
In #4074 we fixed a bug that unfortunately was relied upon in overload resolution of calls to the jQuery function. We decided to keep the bug fix and also fix the unintended reliance on the buggy behavior in the jquery.d.ts definition file.
I see a difference between how TypeScript 1.5 and 1.6 infer the type of function call. I am not sure if this is a bug. I would like to understand if this an indication of something subtle that users of the compiler must know. The shell output that follows illustrates how to reproduce this issue.
These are the two versions of the compiler that I am working with.
hello.ts
has snippet from Definitely Typed's jquery.d.ts commit 1ba21f73e4104d567d64c03c89604e5960ae7f93TypeScript 1.5.3 and 1.6.2 compile the above file differently. 1.6.2 reports a compile error.
hello2.ts
is a different snippet from Definitely Typed's jquery.d.ts commit 1d6c126e8ead25892ded5a32df2e813ffad06905. Note thathello2.ts
andhello.ts
differ in the order of function definitions withininterface JQuery
.Both compiler versions 1.5.3 and 1.6.2 don't report any error when compiling
hello2.ts
.Is the difference in behavior between 1.5.3 and 1.6.2 a regression or an improvement? Why did Definitely Typed's file change the order of the definition of these functions? I could not figure this out fro m the commit message that made the change.
The text was updated successfully, but these errors were encountered: