GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix multiple issues with indexed access types applied to mapped types by ahejlsberg · Pull Request #47109 · microsoft/TypeScript Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
TypeScript Bot (@typescript-bot) perf test faster |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at d42e4c2. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at d42e4c2. You can monitor the build here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at d42e4c2. You can monitor the build here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
TypeScript Bot (@typescript-bot) user test this inline |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the inline community code test suite on this PR at d42e4c2. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg) Here they are:Comparison Report - main..47109
System
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Anders Hejlsberg (@ahejlsberg) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm kind of surprised at how much of this already works in TS4.5 without these fixes. Both processRecord({ kind: 'n', v: 42, f: v => v.toExponential() }); // error fails outright, and that's just because of unfortunate contextual typing of processRecord<'n'>({ kind: 'n', v: 42, f: v => v.toExponential() }); // okay processRecord({ kind: 'n', v: 42, f: (v: number) => v.toExponential() }); // okay Am I right in thinking the current fix is mostly helping inference for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yes, the nice thing is that this approach isn't really a new feature. The core capabilities were all there, they just didn't work quite right in a few cases. This in contrast to a whole new feature like existential types, which would be a very complex undertaking.
The PR has three fixes in it. Two of them relate to inference, specifically that we would fail to infer from object literals that contain contextually typed arrow functions. The third fix relates to indexing non-generic mapped types with generic index types. For example: type RecordFuncMap = { [P in keyof RecordMap]: (x: RecordMap[P]) => void }; const recordFuncs: RecordFuncMap = { n: n => n.toFixed(2), s: s => s.length, b: b => b ? 1 : 0, } function callRecordFunc<K extends keyof RecordMap>(rec: UnionRecord<K>) { const fn = recordFuncs[rec.kind]; // RecordFuncMap[K] fn(rec.v); // Would fail, but works with this PR } The call in There are more examples of this pattern in the tests I just added to the PR. See here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Performance is unaffected by this PR and all tests look clean. I think this is ready to merge. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Anders Hejlsberg fixed issues of version 4.5.4 in microsoft/TypeScript#47109 so I revert typescript version until it will be released Hejlsberg saved my day ❤️
|
I have run into an oddity that might be related to this PR. Consider the following code: enum MyEvent { One, Two } type Callback<T> = (arg: T) => void; interface CallbackTypes { [MyEvent.One]: number [MyEvent.Two]: string } type Callbacks = { [E in MyEvent]: Callback<CallbackTypes[E]>[] }; class CallbackContainer { callbacks: Callbacks = { [MyEvent.One]: [], [MyEvent.Two]: [] }; constructor() { } setListener<E extends MyEvent>(event: E, callback: Callback<CallbackTypes[E]>) { const callbacks = this.callbacks[event]; callbacks.push(callback); // okay } getListeners<E extends MyEvent>(event: E) { return this.callbacks[event]; } } Thanks to this PR above code now works! But when I change Why then, is |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This does some hacky things to get inference that works for the mapping types. Based on: microsoft/TypeScript#47109 Also adds two comments where the expect error cannot reasonably be removed (as far as I can see). Experiment with it here: https://www.typescriptlang.org/play?ts=5.3.3#code/C4TwDgpgBAYglgJwgEwPKQQQ2HA9gOygF4oBvKUSALigCIAzRFWgGigGMIAbLm-AVwC2AIwgIoAXwBQlaAFlcANxTox2PIRLlZNWoKXM2nHnyGiEbMLgDOcHARoBtASLFsX5gLqSZ4aKqx7TVgmNAx1AigAHygFZTC1IKlkgHoUij8oAIjg8kYkZBpUQTsAHngC7KC2WllaAD42fXiikuBSuJVw6ro6+skAbl9ILO6NABVMkiqNR1q-Wk9k2VHEjTlMMFKAaSgIAA9gCHxka1XAib9+rShHAAUoOEJtzxpSKShPjOooO5YpCRQABkWTapQAoocsOx2jMCGxSDpfhJGr0FvUAY4XkNhtAYPx8DD1psdntDsdTuccpNINcyB8vvdHs9XlAABS4MYOKlBDZbO71ACUxH6ilwcGQAOS7AI1mAUHoBKJBD5NHxhN5JLh+BpEDp7y+CtCNDZ+RQAH1OWtuRUutb8IKaGKJSL6YbDWbkJaufgAHTGLgMz4Sf6G5ooE3hr1Wi7czoJWMOp3i5Cug3uz5R732-3cQMZzMGaM+31WWxJQ3SaRSRUajRQTZgLggbWkg5HE5nbW6+ocn1FH18nZC5Mu9OfGX4OVQfbEKAxnK+2RBjiy+W19hzjeasCOfZLD1Kvv2wVSoA Signed-off-by: anderium <[email protected]>
|
This PR is linked from TypeScript 4.6 release notes but the implementation changed soon after it here: #47370 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This does some hacky things to get inference that works for the mapping types. Based on: microsoft/TypeScript#47109 Also adds two comments where the expect error cannot reasonably be removed (as far as I can see). Experiment with it here: https://www.typescriptlang.org/play?ts=5.3.3#code/C4TwDgpgBAYglgJwgEwPKQQQ2HA9gOygF4oBvKUSALigCIAzRFWgGigGMIAbLm-AVwC2AIwgIoAXwBQlaAFlcANxTox2PIRLlZNWoKXM2nHnyGiEbMLgDOcHARoBtASLFsX5gLqSZ4aKqx7TVgmNAx1AigAHygFZTC1IKlkgHoUij8oAIjg8kYkZBpUQTsAHngC7KC2WllaAD42fXiikuBSuJVw6ro6+skAbl9ILO6NABVMkiqNR1q-Wk9k2VHEjTlMMFKAaSgIAA9gCHxka1XAib9+rShHAAUoOEJtzxpSKShPjOooO5YpCRQABkWTapQAoocsOx2jMCGxSDpfhJGr0FvUAY4XkNhtAYPx8DD1psdntDsdTuccpNINcyB8vvdHs9XlAABS4MYOKlBDZbO71ACUxH6ilwcGQAOS7AI1mAUHoBKJBD5NHxhN5JLh+BpEDp7y+CtCNDZ+RQAH1OWtuRUutb8IKaGKJSL6YbDWbkJaufgAHTGLgMz4Sf6G5ooE3hr1Wi7czoJWMOp3i5Cug3uz5R732-3cQMZzMGaM+31WWxJQ3SaRSRUajRQTZgLggbWkg5HE5nbW6+ocn1FH18nZC5Mu9OfGX4OVQfbEKAxnK+2RBjiy+W19hzjeasCOfZLD1Kvv2wVSoA Signed-off-by: anderium <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Wishlist: support for correlated union types
There was an error while loading. Please reload this page.