Title: Functions with overloads don't automatically get types for their parameters · Issue #38625 · microsoft/TypeScript · GitHub
Open Graph Title: Functions with overloads don't automatically get types for their parameters · Issue #38625 · microsoft/TypeScript
X Title: Functions with overloads don't automatically get types for their parameters · Issue #38625 · microsoft/TypeScript
Description: TypeScript Version: 3.9.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.9.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.9.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/38625
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Functions with overloads don't automatically get types for their parameters","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.9.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":"2020-05-17T22:15:02Z","url":"https://github.com/microsoft/TypeScript/issues/38625"}
| 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:b502e220-0382-7b95-2a6b-f5f01ccf991a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD34:19E4BB:719C05:92E5F2:6B00E3FE |
| html-safe-nonce | bc29ad449b7a39c7c24aec08e7ff4e07061648c5778fde85cd43d29e78ad143d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDM0OjE5RTRCQjo3MTlDMDU6OTJFNUYyOjZCMDBFM0ZFIiwidmlzaXRvcl9pZCI6IjUwNDEzMzY3NjYzMjY5NTgwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4185ae4d020158d482df9908ec069ba0c55a050c3998e341a462ba8ca5fa9c6 |
| hovercard-subject-tag | issue:619809029 |
| 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/38625/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7919a2479c80cb9caa6bffb139580e43fd2636b6fdc098c6b9b00d4aa18851ea/microsoft/TypeScript/issues/38625 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7919a2479c80cb9caa6bffb139580e43fd2636b6fdc098c6b9b00d4aa18851ea/microsoft/TypeScript/issues/38625 |
| og:image:alt | TypeScript Version: 3.9.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 | 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