Title: Type-inference difference/regression between 1.5 and 1.6 · Issue #5969 · microsoft/TypeScript · GitHub
Open Graph Title: Type-inference difference/regression between 1.5 and 1.6 · Issue #5969 · microsoft/TypeScript
X Title: Type-inference difference/regression between 1.5 and 1.6 · Issue #5969 · microsoft/TypeScript
Description: 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 o...
Open Graph Description: 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 user...
X Description: 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 user...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5969
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type-inference difference/regression between 1.5 and 1.6","articleBody":"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.\n\nThese are the two versions of the compiler that I am working with.\n\n```\n$ ./1.5.3/node_modules/.bin/tsc --version\nmessage TS6029: Version 1.5.3\n$ ./1.6.2/node_modules/.bin/tsc --version\nmessage TS6029: Version 1.6.2\n```\n\n`hello.ts` has snippet from [Definitely Typed's jquery.d.ts commit 1ba21f73e4104d567d64c03c89604e5960ae7f93](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1ba21f73e4104d567d64c03c89604e5960ae7f93/jquery/jquery.d.ts#L1547)\n\n```\n$ cat hello.ts \n/**\n * A few lines copied from the JQuery type definition to illustrate this\n * bug.\n * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1ba21f73e4104d567d64c03c89604e5960ae7f93/jquery/jquery.d.ts#L1547\n */\ninterface JQuery {\n // 1\n data(key: string, value: any): JQuery;\n // 2\n data(obj: { [key: string]: any; }): JQuery;\n // 3\n data(key: string): any;\n // 4\n data(): any;\n};\n\nfunction caller(jq: JQuery) {\n // We expect the data call below to call version 3 of the data function\n // mentioned above.\n var s: string = jq.data(\"hello\");\n}\n```\n\nTypeScript 1.5.3 and 1.6.2 compile the above file differently. 1.6.2 reports a compile error.\n\n```\n$ ./1.5.3/node_modules/.bin/tsc hello.ts # No error here\n$ ./1.6.2/node_modules/.bin/tsc hello.ts\nhello.ts(20,9): error TS2322: Type 'JQuery' is not assignable to type 'string'.\n```\n\n`hello2.ts` is a different snippet from [Definitely Typed's jquery.d.ts commit 1d6c126e8ead25892ded5a32df2e813ffad06905](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1d6c126e8ead25892ded5a32df2e813ffad06905/jquery/jquery.d.ts#L1547). Note that `hello2.ts` and `hello.ts` differ in the order of function definitions within `interface JQuery`.\n\n```\n$ cat hello2.ts \n/**\n * A few lines copied from the JQuery type definition to illustrate this\n * bug.\n * https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1d6c126e8ead25892ded5a32df2e813ffad06905/jquery/jquery.d.ts#L1547\n */\ninterface JQuery {\n // 1\n data(key: string, value: any): JQuery;\n // 3\n data(key: string): any;\n // 2\n data(obj: { [key: string]: any; }): JQuery;\n // 4\n data(): any;\n};\n\nfunction caller(jq: JQuery) {\n // We expect the data call below to call version 3 of the data function\n // mentioned above.\n var s: string = jq.data(\"hello\");\n}\n```\n\nBoth compiler versions 1.5.3 and 1.6.2 don't report any error when compiling `hello2.ts`.\n\n```\n$ ./1.5.3/node_modules/.bin/tsc hello2.ts # No error\n$ ./1.6.2/node_modules/.bin/tsc hello2.ts # No error\n```\n\nIs 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.\n","author":{"url":"https://github.com/suriya","@type":"Person","name":"suriya"},"datePublished":"2015-12-07T15:00:30Z","url":"https://github.com/microsoft/TypeScript/issues/5969"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:db43eec7-905d-ce6a-9edd-81f5ef2ed68d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8A8:20AA01:9E38A7:CC9C1A:6B00E10F |
| html-safe-nonce | 7f6b64a66f7b6bf820bc7be2c4ddbe23d301f84b39f47671a253098417346172 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEE4OjIwQUEwMTo5RTM4QTc6Q0M5QzFBOjZCMDBFMTBGIiwidmlzaXRvcl9pZCI6IjU5NTMyODYxMjEwNDI1MzQ2NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d43ff4ca54dcfc1cace0bc3cb8f260d497679ff28c1838fe4461269293aac1de |
| hovercard-subject-tag | issue:120792158 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/5969/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8e6d34057b30ea8b3ff36f3327eef910e14048925b522fc190602313f569007e/microsoft/TypeScript/issues/5969 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8e6d34057b30ea8b3ff36f3327eef910e14048925b522fc190602313f569007e/microsoft/TypeScript/issues/5969 |
| og:image:alt | 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 user... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | suriya |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width