Repository navigation
Permit circular references in type arguments for object type aliases - #57293
Anders Hejlsberg (ahejlsberg) wants to merge 3 commits into
Conversation
|
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure Daniel Rosenwasser (@DanielRosenwasser) and Ryan Cavanaugh (@RyanCavanaugh) are aware of the changes, just as a heads up. |
|
TypeScript Bot (@typescript-bot) test top200 |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the faster perf test suite on this PR at ad0a847. You can monitor the build here. Update: The results are in! |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at ad0a847. You can monitor the build here. Update: The results are in! |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at ad0a847. You can monitor the build here. Update: The results are in! Update: The results are in! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user test suite comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Details
|
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top-repos suite comparing Something interesting changed - please have a look. Details
|
|
Anders Hejlsberg (@ahejlsberg) Here are some more interesting changes from running the top-repos suite Details
|
|
Hey Anders Hejlsberg (@ahejlsberg), it looks like the DT test run failed. Please check the log for more details. |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. Branch only errors:Package: ramda Package: redis-info |
|
|
||
| export type Bar = Omit<Foo, "c">; | ||
| >Bar : { a: string; b: number; } | ||
| >Bar : { b: number; a: string; } |
There was a problem hiding this comment.
Why'd this change?
There was a problem hiding this comment.
It has to do with the order in which the literal types were materialized. Because we defer the Omit instantiations, we end up materializing the "b" and "c" literal types before we materialize "a". Since Omit is non-homomorphic and since unions are ordered by type ID, this ends up flipping the properties.
|
TypeScript Bot (@typescript-bot) pack this |
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 81efc86. You can monitor the build here. |
|
Hey Daniel Rosenwasser (@DanielRosenwasser), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
type Loopy1<T> = Loopy2<T>;
type Loopy2<T> = Record<string, keyof Loopy1<T>>;Seems to cause a stack overflow in the playground. |
|
Does this cover the basic case of aliasing a class? class Box<T> {
t!: T;
}
type MyBox<T> = Box<T>;
type Foo = number | Box<Foo>; // this is fine
type Bar = number | MyBox<Bar>; // error, circular referenceI'm hitting this problem in my code, and the alias is needed for other reasons, making this hard to work around. What is the status of this PR? |
|
David Greenspan (@dgreensp) Yes, it covers that scenario. However, it's not clear the implementation approach in the PR is viable, so we're still thinking about solutions. I can say for sure it won't be in the 5.5 release. |
|
Anders Hejlsberg (@ahejlsberg) Seems you dealt with mutually recursive types fine. My cases from #61062 pass fine ! This is great, I will try it in anger on a real world code example ! |
|
Anders Hejlsberg (@ahejlsberg) Yes Daniel Rosenwasser (@DanielRosenwasser) test case causes :- RangeError: Maximum call stack size exceeded |
|
Dissecting :- we get the following :- But not the :- RangeError: Maximum call stack size exceeded so it looks like recursive parameterization over |
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
With this PR we lift a long standing restriction and permit type arguments for object type aliases to circularly reference themselves. For example:
The PR specifically covers circular references in type arguments for type aliases that reference the following kinds of types:
Circular references in type arguments for type aliases that reference other kinds of types still aren't permitted. For example:
Above, instantiations of
TNode<T>andTLeaf<V>are permitted to have circular type arguments because they are type aliases for object types. However,TLevel<V, T>does not permit circular type arguments because it is a type alias for a union type.Fixes #35017.
Fixes #35164.
Fixes #41164.
Fixes #57034.