Title: Functions with overloads don't automatically get types for their parameters · Issue #32037 · microsoft/TypeScript · GitHub
Open Graph Title: Functions with overloads don't automatically get types for their parameters · Issue #32037 · microsoft/TypeScript
X Title: Functions with overloads don't automatically get types for their parameters · Issue #32037 · microsoft/TypeScript
Description: TypeScript Version: 3.5.2 Search Terms: noImplicitAny true overloaded inferred types Code I don't know the exact terms for what's happening in the first example. Are these parameters' "types being inferred"? // `text` has type `string` w...
Open Graph Description: TypeScript Version: 3.5.2 Search Terms: noImplicitAny true overloaded inferred types Code I don't know the exact terms for what's happening in the first example. Are these parameters' "types being ...
X Description: TypeScript Version: 3.5.2 Search Terms: noImplicitAny true overloaded inferred types Code I don't know the exact terms for what's happening in the first example. Are these parameters' &...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32037
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Functions with overloads don't automatically get types for their parameters","articleBody":"\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.5.2\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\n\r\nnoImplicitAny true\r\noverloaded\r\ninferred types\r\n\r\n**Code**\r\n\r\nI don't know the exact terms for what's happening in the first example. Are these parameters' \"types being inferred\"?\r\n\r\n```ts\r\n// `text` has type `string`\r\nwindow.alert = (text) => {\r\n\treturn window.alert(text);\r\n}\r\n\r\n// Both parameters are `any`, because `addEventListener` has overloads\r\nwindow.addEventListener = (type, fn) => {\r\n\treturn window.addEventListener(type, fn);\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nThey should follow these types from `lib.dom.d.ts`:\r\n\r\n```ts\r\naddEventListener\u003cK extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;\r\naddEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\r\n```\r\n\r\n\r\n**Actual behavior:**\r\n```\r\nParameter 'type' implicitly has an 'any' type. ts(7006)\r\nParameter 'fn' implicitly has an 'any' type. ts(7006)\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/#src=window.alert%20%3D%20(text)%20%3D%3E%20%7B%0D%0A%09return%20window.alert(text)%3B%0D%0A%7D%0D%0A%0D%0Awindow.addEventListener%20%3D%20(type%2C%20fn)%20%3D%3E%20%7B%0D%0A%09return%20window.addEventListener(type%2C%20fn)%3B%0D%0A%7D","author":{"url":"https://github.com/fregante","@type":"Person","name":"fregante"},"datePublished":"2019-06-22T05:55:52Z","url":"https://github.com/microsoft/TypeScript/issues/32037"}
| 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:a2171c8f-5c34-f296-3c52-6210e2d74f23 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 884A:2564D8:D32347:11843B6:6B00F962 |
| html-safe-nonce | e3931b3127f4d65a2855460a7718b429afc95d3a5008835b268b12ac519f6699 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODRBOjI1NjREODpEMzIzNDc6MTE4NDNCNjo2QjAwRjk2MiIsInZpc2l0b3JfaWQiOiI0NTA0MDY4NDUwNjE1ODg0MTMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a1abc4ee54d186aca26978de820bd52415a871af21099862d19d8a5d8e6233fb |
| hovercard-subject-tag | issue:459440946 |
| 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/32037/issue_layout |
| twitter:image | https://opengraph.githubassets.com/932afb4d89901c1b9a421971aca6b1e78871b0f25f80c1494ab4185a2eeb9ab7/microsoft/TypeScript/issues/32037 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/932afb4d89901c1b9a421971aca6b1e78871b0f25f80c1494ab4185a2eeb9ab7/microsoft/TypeScript/issues/32037 |
| og:image:alt | TypeScript Version: 3.5.2 Search Terms: noImplicitAny true overloaded inferred types Code I don't know the exact terms for what's happening in the first example. Are these parameters' "types being ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fregante |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width