Title: Type Inference on function arguments · Issue #15114 · microsoft/TypeScript · GitHub
Open Graph Title: Type Inference on function arguments · Issue #15114 · microsoft/TypeScript
X Title: Type Inference on function arguments · Issue #15114 · microsoft/TypeScript
Description: TypeScript Version: 2.3.0 Code function f(x: number){ return x; } function g(x){ return x}; function h(x){ return f(x); }; Expected behavior: I would expect the inferred type of g to be (x:any)=>any, and the infered type of h to be (x:nu...
Open Graph Description: TypeScript Version: 2.3.0 Code function f(x: number){ return x; } function g(x){ return x}; function h(x){ return f(x); }; Expected behavior: I would expect the inferred type of g to be (x:any)=>an...
X Description: TypeScript Version: 2.3.0 Code function f(x: number){ return x; } function g(x){ return x}; function h(x){ return f(x); }; Expected behavior: I would expect the inferred type of g to be (x:any)=>...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15114
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type Inference on function arguments","articleBody":"**TypeScript Version:** \r\n2.3.0 \r\n\r\n**Code**\r\n\r\n```ts\r\nfunction f(x: number){\r\n return x;\r\n}\r\n\r\nfunction g(x){ return x};\r\n\r\nfunction h(x){ return f(x); };\r\n```\r\n\r\n**Expected behavior:**\r\nI would expect the inferred type of `g` to be `(x:any)=>any`, and the infered type of `h` to be `(x:number) => number` (due to the restrictions placed by the call of `f`)\r\n\r\nWhen compiling with `noImplicitAny`, I would only expect an error on `g`, not on `h`\r\n\r\n**Actual behavior:**\r\nRunning `tsc --declaration` on this snippet gives me:\r\n\r\n```ts\r\ndeclare function f(x: number): number;\r\ndeclare function g(x: any): any;\r\ndeclare function h(x: any): number;\r\n```\r\n\r\nthe `x` argument on `h` does not seem to use the `f(x)` call to tighten the definition. \r\n\r\nConsidering the simplicity of the example, I imagine I might be missing an important detail in the type system that makes this the proper inference result, but I haven't figured it out yet.\r\n\r\n","author":{"url":"https://github.com/rtpg","@type":"Person","name":"rtpg"},"datePublished":"2017-04-11T01:51:41Z","url":"https://github.com/microsoft/TypeScript/issues/15114"}
| 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:9b9a679a-aa6c-f704-e109-e8ff9f751e03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96F4:1D86C4:836FFC:A878C7:6B00E8DA |
| html-safe-nonce | cadc0599cb6b750e82187f880def25b13e089c1c055b421e62f702ed719bbc28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkY0OjFEODZDNDo4MzZGRkM6QTg3OEM3OjZCMDBFOERBIiwidmlzaXRvcl9pZCI6IjM1MTU3MDE1OTAzNjU5MDI5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aacdcbf2d289bac67012cfb52fe94a9d24cadc93b1758e027c77f15ec74fcc34 |
| hovercard-subject-tag | issue:220817118 |
| 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/15114/issue_layout |
| twitter:image | https://opengraph.githubassets.com/397c337da5d43ace16aaf67151a234bc956b6311b60cab8543e6c72c23ca52ff/microsoft/TypeScript/issues/15114 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/397c337da5d43ace16aaf67151a234bc956b6311b60cab8543e6c72c23ca52ff/microsoft/TypeScript/issues/15114 |
| og:image:alt | TypeScript Version: 2.3.0 Code function f(x: number){ return x; } function g(x){ return x}; function h(x){ return f(x); }; Expected behavior: I would expect the inferred type of g to be (x:any)=>an... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rtpg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width