Title: Generic inference different between equivalent function expression and shorthand method in object literal (vol 2) · Issue #34849 · microsoft/TypeScript · GitHub
Open Graph Title: Generic inference different between equivalent function expression and shorthand method in object literal (vol 2) · Issue #34849 · microsoft/TypeScript
X Title: Generic inference different between equivalent function expression and shorthand method in object literal (vol 2) · Issue #34849 · microsoft/TypeScript
Description: TypeScript Version: 3.6.3 - 3.8.0-dev.20191031 Search Terms: parameter, inference, order, generic, function expression, function declaration Code interface IData { bar: boolean } declare function test
Open Graph Description: TypeScript Version: 3.6.3 - 3.8.0-dev.20191031 Search Terms: parameter, inference, order, generic, function expression, function declaration Code interface IData { bar: boolean } declare function t...
X Description: TypeScript Version: 3.6.3 - 3.8.0-dev.20191031 Search Terms: parameter, inference, order, generic, function expression, function declaration Code interface IData { bar: boolean } declare function t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/34849
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic inference different between equivalent function expression and shorthand method in object literal (vol 2)","articleBody":"**TypeScript Version:** 3.6.3 - 3.8.0-dev.20191031\r\n\r\n**Search Terms:** parameter, inference, order, generic, function expression, function declaration\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface IData {\r\n bar: boolean\r\n}\r\n\r\ndeclare function test\u003cTDependencies>(\r\n getter: (deps: TDependencies, data: IData) => any,\r\n deps: TDependencies,\r\n): any \r\n\r\nconst DEPS = {\r\n foo: 1\r\n}\r\n\r\n// negative test\r\ntest(\r\n (deps, data) => ({\r\n fn1: function() { return deps.foo },\r\n fn2: data.bar\r\n }),\r\n DEPS\r\n);\r\n\r\n// positive tests\r\ntest(\r\n (deps: typeof DEPS, data) => ({\r\n fn1: function() { return deps.foo },\r\n fn2: data.bar\r\n }),\r\n DEPS\r\n);\r\n\r\ntest(\r\n (deps, data) => ({\r\n fn1: () => deps.foo,\r\n fn2: data.bar\r\n }),\r\n DEPS\r\n);\r\n\r\ntest(\r\n (deps, data) => {\r\n return {\r\n fn1() { return deps.foo },\r\n fn2: data.bar\r\n }\r\n },\r\n DEPS\r\n);\r\n\r\ntest(\r\n (deps) => ({\r\n fn1() { return deps.foo },\r\n fn2: 1\r\n }),\r\n DEPS\r\n);\r\n```\r\n\r\n**Expected behavior:** `deps` should be inferred as `typeof DEPS` in negative test\r\n\r\n**Actual behavior:** `deps` inferred as unknown\r\n\r\n**Playground Link:** [link](http://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=56&pc=3#code/JYOwLgpgTgZghgYwgAgJIBE5jsg3gWAChlkAjOKALjIHsaAbCOEIgXyKIBMIF6KUYAVxAIwwGiGSQAzmAA8AFXQQADhBDcRwCNIB8ACiIkA5hDCQqyfdxXTqS1es0Jt0gDTJOWONQzeAlMgAvLrIzACebkaeqnbIDmoa6i46UYT+1BHIHIQIErLI6ACiAAoAysF40TB01ACMbDkA9E3IIBDGWMAAbigyYET9hsRWNu6eAcGh+gQjJDAgddRCImIS+oG4yFBmglCSYwB0NTTIrGkk8yAATNRe2IfkUNGs-heFpWVE-gDcza0qGjSYBiXpSHRgaSDCHDEjWWLUMDhNQ0GAfcoee5wQIhKyzS7IBZLQnCUTiEAbPDbXb7GK2Y50M7vK63CYPJ4vN7RYrlb5-QjQ2Sw0axTGTXEzaJXYmU3FHE7Mwk3O7eR4UTnvHlfdL8wVgYXw2xi7A40L4y47MB7STmglEylbS3WunSBmnc5Sy4LVlYtXPOZnF6az58nJDaKG6SmvGe+2balW2nyxkegPe+oa7khnVAA)\r\n**Related Issues:** I guess, the fix of #32230 bug led to the appearance of this bug\r\n","author":{"url":"https://github.com/iKBAHT","@type":"Person","name":"iKBAHT"},"datePublished":"2019-10-31T14:15:48Z","url":"https://github.com/microsoft/TypeScript/issues/34849"}
| 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:45e463e7-55fa-f21c-b7f8-31340b22555a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFDE:29FFA9:2B6754F:36F8FFF:6B01AA61 |
| html-safe-nonce | 6b2cbcac927d170b4b74a7aa23d8470b693c6f08e29664d97385edef1387b3d1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkRFOjI5RkZBOToyQjY3NTRGOjM2RjhGRkY6NkIwMUFBNjEiLCJ2aXNpdG9yX2lkIjoiNzMyOTY1MDg0MjUwMjUzOTg3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b6440be88c231b6919605de1e7281d4d3d1b3027362ca5bd714bee89a35f51af |
| hovercard-subject-tag | issue:515467827 |
| 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/34849/issue_layout |
| twitter:image | https://opengraph.githubassets.com/98154670d6d380cc1bee1d0bd3013212628667d9dc53cf31c9240556ce5a5c9c/microsoft/TypeScript/issues/34849 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/98154670d6d380cc1bee1d0bd3013212628667d9dc53cf31c9240556ce5a5c9c/microsoft/TypeScript/issues/34849 |
| og:image:alt | TypeScript Version: 3.6.3 - 3.8.0-dev.20191031 Search Terms: parameter, inference, order, generic, function expression, function declaration Code interface IData { bar: boolean } declare function t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iKBAHT |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width