Title: Contravariance broke in 3.8 when combining spreading parameter list with conditional type · Issue #37400 · microsoft/TypeScript · GitHub
Open Graph Title: Contravariance broke in 3.8 when combining spreading parameter list with conditional type · Issue #37400 · microsoft/TypeScript
X Title: Contravariance broke in 3.8 when combining spreading parameter list with conditional type · Issue #37400 · microsoft/TypeScript
Description: TypeScript Version: 3.8.3 Search Terms: variance contravariance Description: An Injector in typed-inject is a dependency injection container that is type safe. It can only provide values for tokens it knows. A small example: declare cons...
Open Graph Description: TypeScript Version: 3.8.3 Search Terms: variance contravariance Description: An Injector in typed-inject is a dependency injection container that is type safe. It can only provide values for tokens...
X Description: TypeScript Version: 3.8.3 Search Terms: variance contravariance Description: An Injector in typed-inject is a dependency injection container that is type safe. It can only provide values for tokens...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/37400
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Contravariance broke in 3.8 when combining spreading parameter list with conditional type","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n**TypeScript Version:** 3.8.3\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** variance contravariance\r\n\r\n**Description**: An Injector in [typed-inject](https://github.com/nicojs/typed-inject) is a dependency injection container that is type safe. It can only provide values for tokens it knows. A small example:\r\n\r\n```ts\r\ndeclare const fooInjector: Injector\u003c{foo: string}>; // this injector can provide string values for the token 'foo'\r\nconst foo = fooInjector.resolve('foo'); \r\n// => typeof foo === 'string'\r\nfooInjector.resolve('bar');\r\n// => Error ts(2345) Argument of type '\"bar\"' is not assignable to parameter of type '\"foo\"'\r\n```\r\n\r\nIt makes sense that an injector `Injector\u003c{}>` is not assignable to `Injector\u003c{foo: string}>`, since it cannot provide a value for token `'foo'`. This was the case in TS 3.7. However, since TS 3.8, `Injector\u003c{}>` _is_ assignable to `Injector\u003c{foo: string}>` 😪.\r\n\r\n```ts\r\ndeclare const rootInjector: Injector\u003c{}>;\r\nconst fooInjector: Injector\u003c{ foo: string}> = rootInjector;\r\n```\r\n\r\n**Expected behavior:** `Type 'Injector\u003c{}>' is not assignable to type 'Injector\u003c{ foo: string; }>'.`\r\n\r\n**Actual behavior:** No error\r\n\r\n\u003c!-- Did you find other bugs that looked similar? -->\r\n**Related Issues:** Couldn't find any 🤷♂️\r\n\r\n**Code**\r\n\r\nI think I've trimmed it down to the essentials.\r\n\r\n```ts\r\ninterface Injector\u003cTContext> {\r\n injectFunction\u003cTokens extends (keyof TContext)[]>(todo:\r\n (...args: { [K in keyof Tokens]: Tokens[K] extends keyof TContext ? TContext[Tokens[K]] : never; }) => void): void;\r\n} \r\n\r\ndeclare const rootInjector: Injector\u003c{}>;\r\nconst fooInjector: Injector\u003c{ foo: string}> = rootInjector;\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n(none)\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"alwaysStrict\": true,\r\n \"esModuleInterop\": true,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": true,\r\n \"emitDecoratorMetadata\": true,\r\n \"moduleResolution\": 2,\r\n \"target\": \"ES2017\",\r\n \"jsx\": \"React\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgJIgFYQWA9lAHgBUBhXcCADzAD5kBvAKGWVCxwDEBXEHYc4rgDWEEAGdkVSCAAmEgBQiAnrhjJS5SNQCUAbQC6NeXhm4AXMxbJ5AOjtwoAczFmGyXQGlWIZMtXrhUTF9VyJA8U99SWpROV8IFTUNCmpkAH51MhSwXTCRCI99KNcQCAA3aABuZABfbWQAXjoy3GAZbVcWtsrGGuRGRhlsABsHFARyMTBkKFxcMHR2PChXRexlgnoamh6J8WmYObWcfFXMdfxN5EPzZCmoUEdtxpm5hfOTqB6gA)\r\n \r\nSimpler contravariant examples like this still work as expected.\r\n\r\n```ts\r\ntype Action\u003cT> = (arg: T) => void;\r\ndeclare let b: Action\u003c{}>;\r\ndeclare let a: Action\u003c{foo: number}>;\r\nb = a\r\n// => Error! Type 'Action\u003c{ foo: number; }>' is not assignable to type 'Action\u003c{}>'.\r\n```\r\n\r\n","author":{"url":"https://github.com/nicojs","@type":"Person","name":"nicojs"},"datePublished":"2020-03-14T22:38:40Z","url":"https://github.com/microsoft/TypeScript/issues/37400"}
| 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:80552359-b898-3195-f566-7e8d12a776a9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DF0A:DB09F:C99683:1022BD2:6B010291 |
| html-safe-nonce | bbf8e2d76e8ded99a5e260addd4db831b3ab189b5c4f7f9759e1ea511aeb42b0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjBBOkRCMDlGOkM5OTY4MzoxMDIyQkQyOjZCMDEwMjkxIiwidmlzaXRvcl9pZCI6IjQ5MzczMDIzNjQ0MDQxMjIyNTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d3da22b0497a11dd1116af65a2fdf12a2cc3816e739e1012e3c71e297b5e15f6 |
| hovercard-subject-tag | issue:581401922 |
| 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/37400/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d60be9d5c45bf6420d2a62d16e12ad30ee26bd82cab4f934dfefa142caeaefa6/microsoft/TypeScript/issues/37400 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d60be9d5c45bf6420d2a62d16e12ad30ee26bd82cab4f934dfefa142caeaefa6/microsoft/TypeScript/issues/37400 |
| og:image:alt | TypeScript Version: 3.8.3 Search Terms: variance contravariance Description: An Injector in typed-inject is a dependency injection container that is type safe. It can only provide values for tokens... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nicojs |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width