Title: Function shapes with union typed params incorrectly accept more restrictive functions · Issue #9765 · microsoft/TypeScript · GitHub
Open Graph Title: Function shapes with union typed params incorrectly accept more restrictive functions · Issue #9765 · microsoft/TypeScript
X Title: Function shapes with union typed params incorrectly accept more restrictive functions · Issue #9765 · microsoft/TypeScript
Description: TypeScript Version: 2.0.0 beta Functions typed to accept union typed params incorrectly typecheck against functions whose params only match a subset of the union. Example: interface Callback { (value: string | number): void; } // expect ...
Open Graph Description: TypeScript Version: 2.0.0 beta Functions typed to accept union typed params incorrectly typecheck against functions whose params only match a subset of the union. Example: interface Callback { (val...
X Description: TypeScript Version: 2.0.0 beta Functions typed to accept union typed params incorrectly typecheck against functions whose params only match a subset of the union. Example: interface Callback { (val...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9765
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function shapes with union typed params incorrectly accept more restrictive functions","articleBody":"**TypeScript Version:** 2.0.0 beta\n\nFunctions typed to accept union typed params incorrectly typecheck against functions whose params only match a subset of the union. Example:\n\n``` ts\ninterface Callback {\n (value: string | number): void;\n}\n\n// expect this to work\nconst many: Callback = (value: string | number | boolean) => {\n // ...\n}\n\n// expect a type error here\nconst one: Callback = (value: string) => {\n // ...\n}\n\nmany(1); // should work, does work\none(1); // shouldn't work, does work *\nmany(\"hello\"); // should work, does work\none(\"hello\"); // should work, does work\nmany(true); // shouldn't work, doesn't work\none(true); // shouldn't work, doesn't work\n```\n\n**Expected**\n`one` throws a type error, since `string | number` is not assignable to `string`.\n\n**Actual**\n`one` compiles fine.\n\nThis comes up in real code when declaring a callback whose params may not be defined, e.g.\n\n``` ts\ninterface SomeLib {\n onChange: (callback: (newValue: string | null) => void) => void;\n}\n\nconst foo: SomeLib = ...;\nfoo.onChange((newValue: string) => {\n // oops, I forgot newValue may not be defined, but this compiles\n});\n```\n","author":{"url":"https://github.com/lucasray","@type":"Person","name":"lucasray"},"datePublished":"2016-07-15T20:21:27Z","url":"https://github.com/microsoft/TypeScript/issues/9765"}
| 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:ed24ec0a-49e2-a2c1-d6de-7d2eea769c66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0FE:154D88:163FA3A:1C5FE3C:6B0176A3 |
| html-safe-nonce | 4814decbbe39924f620f884db6551ccb95ca720376ab3e3422eff1a536ece2f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEZFOjE1NEQ4ODoxNjNGQTNBOjFDNUZFM0M6NkIwMTc2QTMiLCJ2aXNpdG9yX2lkIjoiODg2NTQ4ODY4NzUwNTQzODM3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b331bcf686d516686230c3463221ec62fe90a22c8fdd76250bf0dbe8feb2b888 |
| hovercard-subject-tag | issue:165869885 |
| 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/9765/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eab2b8ab943653606eb604c4001d5b21ab2d2040d2e28a3bfbdb3a018f61902f/microsoft/TypeScript/issues/9765 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eab2b8ab943653606eb604c4001d5b21ab2d2040d2e28a3bfbdb3a018f61902f/microsoft/TypeScript/issues/9765 |
| og:image:alt | TypeScript Version: 2.0.0 beta Functions typed to accept union typed params incorrectly typecheck against functions whose params only match a subset of the union. Example: interface Callback { (val... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lucasray |
| 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