-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Permit circular references in type arguments for object type aliases #57293
base: main
Are you sure you want to change the base?
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 @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@typescript-bot test top200 |
Heya @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 @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 @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! |
@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
|
@ahejlsberg Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@ahejlsberg Here are the results of running the top-repos suite comparing Something interesting changed - please have a look. Details
|
@ahejlsberg Here are some more interesting changes from running the top-repos suite Details
|
Hey @ahejlsberg, it looks like the DT test run failed. Please check the log for more details. |
Hey @ahejlsberg, the results of running the DT tests are ready. Branch only errors:Package: ramda
Package: redis-info
|
@@ -13,7 +13,7 @@ interface Foo { | |||
} | |||
|
|||
export type Bar = Omit<Foo, "c">; | |||
>Bar : { a: string; b: number; } | |||
>Bar : { b: number; a: string; } |
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.
Why'd this change?
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.
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 pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 81efc86. You can monitor the build here. |
Hey @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 reference I'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? |
@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. |
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.