Repository navigation
Distinguish between non-distributed and distributed type parameters in mapped types too #65666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mateusz Burzyński (Andarist)
wants to merge
13
commits into
microsoft:main
Choose a base branch
from
Andarist:mapped-type-parameters-rebased-fresh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7abf266
Distinguish between non-distributed and distributed type parameters i…
Andarist 1b7e5ac
Distribute only the template of homomorphic mapped types and normaliz…
Andarist 2a747e3
Normalize distributed type parameters when replacing indexed accesses…
Andarist 1b83aa6
Add tests for nested reverse mapped type inference
Andarist c685769
Add test for nested reverse mapped tuple inference
Andarist 10ef8f1
Normalize generic mapped source templates when relating them to strin…
Andarist c78f095
Skip parentheses when detecting distributive contexts
Andarist 002cf66
Add unconstrained counterpart to the nested reverse mapped tuple infe…
Andarist 3363a46
Add tests for inference to homomorphic mapped types nested in conditi…
Andarist 8eae5b4
Add tests for homomorphic mapped types instantiated for distributed t…
Andarist 3e5991c
Only normalize declared homomorphic mapped types over non-distributed…
Andarist f4b2e0f
Only normalize the target when relating generic mapped types
Andarist 2097b42
Add mapped type counterparts of the distributed conditional type tests
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //// [tests/cases/compiler/distributedMappedTypeIndexSignature.ts] //// | ||
|
|
||
| === distributedMappedTypeIndexSignature.ts === | ||
| type Alias<T> = { [K in keyof T]: (state: T) => void }; | ||
| >Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) | ||
| >K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 0, 19)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 0, 35)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) | ||
|
|
||
| type Check<T, X extends { [x: string]: (state: T) => void }> = X; | ||
| >Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 1, 11)) | ||
| >X : Symbol(X, Decl(distributedMappedTypeIndexSignature.ts, 1, 13)) | ||
| >x : Symbol(x, Decl(distributedMappedTypeIndexSignature.ts, 1, 27)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 1, 40)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 1, 11)) | ||
| >X : Symbol(X, Decl(distributedMappedTypeIndexSignature.ts, 1, 13)) | ||
|
|
||
| type Use1<T> = Check<T, Alias<T>>; | ||
| >Use1 : Symbol(Use1, Decl(distributedMappedTypeIndexSignature.ts, 1, 65)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) | ||
| >Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) | ||
| >Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) | ||
|
|
||
| type Use2<T> = Check<T, { [K in keyof T]: (state: T) => void }>; | ||
| >Use2 : Symbol(Use2, Decl(distributedMappedTypeIndexSignature.ts, 2, 34)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) | ||
| >Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) | ||
| >K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 3, 27)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 3, 43)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) | ||
|
|
||
| function f<T>(alias: Alias<T>, inline: { [K in keyof T]: (state: T) => T[K] }) { | ||
| >f : Symbol(f, Decl(distributedMappedTypeIndexSignature.ts, 3, 64)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >alias : Symbol(alias, Decl(distributedMappedTypeIndexSignature.ts, 5, 14)) | ||
| >Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >inline : Symbol(inline, Decl(distributedMappedTypeIndexSignature.ts, 5, 30)) | ||
| >K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 5, 42)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 5, 58)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 5, 42)) | ||
|
|
||
| const a: Record<string, (state: T) => unknown> = alias; | ||
| >a : Symbol(a, Decl(distributedMappedTypeIndexSignature.ts, 6, 9)) | ||
| >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 6, 29)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >alias : Symbol(alias, Decl(distributedMappedTypeIndexSignature.ts, 5, 14)) | ||
|
|
||
| const b: Record<string, (state: T) => unknown> = inline; | ||
| >b : Symbol(b, Decl(distributedMappedTypeIndexSignature.ts, 7, 9)) | ||
| >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
| >state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 7, 29)) | ||
| >T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) | ||
| >inline : Symbol(inline, Decl(distributedMappedTypeIndexSignature.ts, 5, 30)) | ||
| } | ||
|
|
36 changes: 36 additions & 0 deletions
36
tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //// [tests/cases/compiler/distributedMappedTypeIndexSignature.ts] //// | ||
|
|
||
| === distributedMappedTypeIndexSignature.ts === | ||
| type Alias<T> = { [K in keyof T]: (state: T) => void }; | ||
| >Alias : Alias<T> | ||
| >state : T | ||
|
|
||
| type Check<T, X extends { [x: string]: (state: T) => void }> = X; | ||
| >Check : X | ||
| >x : string | ||
| >state : T | ||
|
|
||
| type Use1<T> = Check<T, Alias<T>>; | ||
| >Use1 : Alias<T> | ||
|
|
||
| type Use2<T> = Check<T, { [K in keyof T]: (state: T) => void }>; | ||
| >Use2 : { [K in keyof T]: (state: T) => void; } | ||
| >state : T | ||
|
|
||
| function f<T>(alias: Alias<T>, inline: { [K in keyof T]: (state: T) => T[K] }) { | ||
| >f : <T>(alias: Alias<T>, inline: { [K in keyof T]: (state: T) => T[K]; }) => void | ||
| >alias : Alias<T> | ||
| >inline : { [K in keyof T]: (state: T) => T[K]; } | ||
| >state : T | ||
|
|
||
| const a: Record<string, (state: T) => unknown> = alias; | ||
| >a : Record<string, (state: T) => unknown> | ||
| >state : T | ||
| >alias : Alias<T> | ||
|
|
||
| const b: Record<string, (state: T) => unknown> = inline; | ||
| >b : Record<string, (state: T) => unknown> | ||
| >state : T | ||
| >inline : { [K in keyof T]: (state: T) => T[K]; } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a gap in the original design of distributed type parameters, which only recognizes a type parameter referenced directly. Conditional types have it too:
Alias<T> extends unknown ? Show<T, U> : neverdistributes overTbut reports no error. Mapped types follow the same syntactic rule here, so I am leaving this out of this PR.Proof: