-
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
Do not measure variance for a conditional type extendsType #31277
Do not measure variance for a conditional type extendsType #31277
Conversation
ping @weswigham |
This PR does not address variance issues stemming from check types (see #31295 as an example). I wonder if it is best to try and fix them together? |
ping @ahejlsberg @weswigham |
1 similar comment
ping @ahejlsberg @weswigham |
@jack-williams can you sync this? We'd want to test this across DT with perf in mind before merging it, which is our primary concern with using |
@weswigham done! |
@typescript-bot run dt |
Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 70336e6. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @weswigham, I've started to run the extended test suite on this PR at 70336e6. You can monitor the build here. It should now contribute to this PR's status checks. |
@jack-williams Can you resolve the errors? @weswigham Can you run @typescript-bot pack this? |
Sure - @typescript-bot pack this |
Heya @weswigham, I've started to run the tarball bundle task on this PR at 70336e6. You can monitor the build here. It should now contribute to this PR's status checks. |
Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
Thanks. @jack-williams Comparison targets are still reversed:
It should be - Type 'ModelType<any>' is not assignable to type 'ModelType<Book>'.
+ Type 'ModelType<Book>' is not assignable to type 'ModelType<any>'. |
@falsandtru can you give me the full example? This might be an issue with the check type, not the extends type. |
Should it? The type appears in an argument position so I would expect them to be flipped when running I don't really have time to debug DT right now, but I wouldn't be surprised if this was correctly an error, something along the line of: interface Foo<T,U> {
x: T extends U ? number : string;
}
declare const a: Foo<any, boolean>;
let b: Foo<boolean, boolean> = a; // no error, but it should be |
I referred to that line to explain the comparison order. Of course it should be no error if any type makes no errors. |
@typescript-bot run dt because the old builds logs were cleared up. |
Heya @jack-williams, I've started to run the parallelized Definitely Typed test suite on this PR at 52c7dff. You can monitor the build here. It should now contribute to this PR's status checks. |
I need to look into some of the changes to see whether they are reasonable, and more likely, what is the corresponding fix. Most of them seem to be cases where something is constrained with a type |
I believe that. What we've been trying to do as of late is to fix the breaks on DT (via PRs to DT) such that we can get a clean run on the PR. It normally works out pretty well in cases like these where you can say "this was a possible way the old types could have been misused, TS with this new PR catches this, and this change preemptively fixes the package so it won't be broken by the next TS release". |
src/compiler/checker.ts
Outdated
if (isTypeIdenticalTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType) && | ||
(isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) || isRelatedTo((<ConditionalType>target).checkType, (<ConditionalType>source).checkType))) { | ||
const u1 = instantiateType((<ConditionalType>source).extendsType, reportUnmeasurableMarkers); | ||
const u2 = instantiateType((<ConditionalType>target).extendsType, reportUnmeasurableMarkers); |
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.
The source and target are identical sans type parameter instantiations during variance checking, so I've been wondering if we can get away with only instantiating one of the source or target.
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.
Yeah that feels like it should work. At least, I don't see how replacing a type parameter with a sub/super type of itself could affect whether it gets instantiated.
Can you merge? |
I found a regression on https://github.com/falsandtru/spica.
|
The error come from
At the following place,
|
@jack-williams pointed out this is still open on #36138. Did you get the chance to take a look at this @ahejlsberg? |
#31277 (comment) is missing. Can you pack again? |
@typescript-bot pack this |
Heya @jack-williams, I've started to run the tarball bundle task on this PR at aa4138d. You can monitor the build here. It should now contribute to this PR's status checks. |
Hm, the task has failed. |
…nds-type-is-unmeasurable
@typescript-bot pack this |
Heya @jack-williams, I've started to run the tarball bundle task on this PR at 81943cc. You can monitor the build here. It should now contribute to this PR's status checks. |
Hey @jack-williams, 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. |
Thanks. I cleaned the related type functions by removing unnecessary constraints but that made no effect. The current errors are as follows.
|
It sounds like this PR is currently blocked on #30639. Is that a correct reading of the comment history @jack-williams? |
@sandersn Blocked may be too strong, but I think it makes sense to merge #30639 first, if possible. This PR makes the compiler check more conditional types structurally, so having more relation rules seems good. I believe #30639 would change some of the breaks introduced by this PR, but I haven't checked DT in a while. |
@jack-williams #30639 got merged this release! Do we need to refresh/reevaluate breaks? I imagine so since the last update in here was march of last year. |
@weswigham I've started trying to revive this. There is one new regression in the compiler tests which I have not been able to figure out yet, but I have been able to reduce to a small example: type EqualsTest<T> = <A>() => A extends T ? 1 : 0;
type EqualsTest1<T> = <A>() => A extends T ? 1 : 0;
const x: EqualsTest<number> = undefined as any as EqualsTest<string>; // was error, now no error
const y: EqualsTest<number> = undefined as any as EqualsTest1<string>; // error; Both used to fail, now only |
Information loss during generic signature relating due to local type parameters erasure is I think likely at fault there, like I (tried to) explain in #43867. |
Specifically the self-assignment case lacks the error because we have a "fast path" in signature comparison (in I have just put together a composition of this change, the change in #41067, and what I just explained, which seems to neatly tie all this together and get our conditionals-in-generic-signatures relationships to where I think it should be. I've put up #43887 with that. |
Thanks @weswigham, your description on the first thread was clear, I just didn't read it in enough detail. The I will close this up in favor of your new PR. Without your change this PR break |
Attempts to fix #31251