Distinguish between non-distributed and distributed type parameters - #64237
Distinguish between non-distributed and distributed type parameters#64237Anders Hejlsberg (ahejlsberg) wants to merge 7 commits into
Conversation
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
TypeScript Bot (@typescript-bot) user test this |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Details
|
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 1000 repos with tsc comparing Something interesting changed - please have a look. Details
|
|
TypeScript Bot (@typescript-bot) test top1000 |
|
TypeScript Bot (@typescript-bot) user test this |
There was a problem hiding this comment.
🟡 Changes recommended
Type serialization can now panic on nil input, and the new hover behavior lacks language-service coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Distinguishes distributed type parameters during conditional-type checking to detect previously missed constraint violations.
Changes:
- Tracks distributed and non-distributed type parameters separately.
- Adds targeted diagnostics and compiler baselines.
- Labels distributed parameters in hover information.
File summaries
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Creates and handles distributed parameter types. |
tsc/internal/checker/types.go |
Stores distributed parameter state. |
tsc/internal/checker/exports.go |
Exposes distributed-state detection. |
tsc/internal/checker/mapper.go |
Normalizes parameters during mapping. |
tsc/internal/checker/inference.go |
Normalizes inference and template matching. |
tsc/internal/checker/relater.go |
Reports constraint violations. |
tsc/internal/checker/nodecopy.go |
Accounts for normalized mapped parameters. |
tsc/internal/checker/nodebuilderimpl.go |
Normalizes parameters during serialization. |
tsc/internal/ls/hover.go |
Adds the distributed hover label. |
tsc/internal/diagnostics/diagnosticMessages.json |
Defines the new diagnostic. |
tsc/internal/diagnostics/diagnostics_generated.go |
Regenerates diagnostic bindings. |
tsc/testdata/tests/cases/compiler/distributedTypeParameters.ts |
Adds compiler regression cases. |
tsc/testdata/baselines/reference/compiler/distributedTypeParameters.errors.txt |
Records expected diagnostics. |
tsc/testdata/baselines/reference/compiler/distributedTypeParameters.types |
Records expected types. |
tsc/testdata/baselines/reference/compiler/distributedTypeParameters.symbols |
Records expected symbols. |
Review details
Files not reviewed (1)
- tsc/internal/diagnostics/diagnostics_generated.go: Generated file
- Files reviewed: 14/15 changed files
- Comments generated: 2
- Review effort level: Balanced
| } | ||
|
|
||
| func (b *NodeBuilderImpl) typeToTypeNode(t *Type) *ast.TypeNode { | ||
| t = getNonDistributedTypeParameter(t) |
There was a problem hiding this comment.
Now fixed.
| if ast.IsIdentifier(node) && ast.IsTypeReferenceNode(node.Parent) && checker.IsDistributedTypeParameter(c.GetTypeAtLocation(node.Parent)) { | ||
| dpw.WritePunctuation("(") | ||
| dpw.Write("distributed") | ||
| dpw.WritePunctuation(") ") | ||
| } |
There was a problem hiding this comment.
Addressed in fd9306a by adding a Fourslash quick-info regression test covering distributed check, extends, true, and false type occurrences plus a non-distributed occurrence.
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 1000 repos with tsc comparing Something interesting changed - please have a look. Details
|
With this PR we distinguish between non-distributed and distributed type parameters in conditional types. Previously we didn't which could lead to constraint violations. In the example
we previously didn't report a constraint violation on
Show<A, B>. We now report a new errorA type parameter is considered to be distributed when it is referenced within a conditional type that distributes that type parameter. Specfically, in a conditional type
T extends XXX ? AAA : BBB,Tis considered distributed within the typesXXX,AAA, andBBB.The distributed form of a type parameter is a subtype of the non-distributed form of that type parameter, and behaves accordingly. In the
Issue<A, B extends A>type above,Bis known to extend the non-distributedA, but that doesn't imply it extends the distributedA, which is a subtype of the non-distributedA. For example, the typeIssue<0 | 1, 0>creates a union ofShow<0, 0>andShow<1, 0>, the second of which violates the constraints declared inShow<T, U extends T>.The language service now shows
(distributed)when hovering over distributed type parameters:This makes it easier to recognize when a type parameter is distributed.
Fixes #63708.