Skip to content
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

Fixed some variance measurements in type aliases of generic functions #54866

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jul 3, 2023

An experiment on how the variance measurement could be improved when intersections and unions are involved in situations like this.

related to the issue found here, cc @RyanCavanaugh

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 3, 2023
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@@ -223,6 +226,10 @@ immutable.ts(391,22): error TS2430: Interface 'Set<T>' incorrectly extends inter
export function Stack<T>(): Stack<T>;
export function Stack<T>(collection: Iterable<T>): Stack<T>;
export interface Stack<T> extends Collection.Indexed<T> {
~~~~~
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a hard time assessing if this is a good change or not, could use some help with that 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a good change. This used to stack out, using more variance calculations removed the stack out, but I think have been hiding the error with incorrect results.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this change looked familiar - I'd built this into the suite of changes in #43887 long ago. I do think this is very much still needed, and since it can stand on its' own, we should probably take it (though I am biased and should get someone else to peek at it). There's a bit more that you should handle, like propagating this "erased" type through indexed access operations, similarly to how wildcardType already works, and any other type constructor that wildcards propagate through.

@@ -223,6 +226,10 @@ immutable.ts(391,22): error TS2430: Interface 'Set<T>' incorrectly extends inter
export function Stack<T>(): Stack<T>;
export function Stack<T>(collection: Iterable<T>): Stack<T>;
export interface Stack<T> extends Collection.Indexed<T> {
~~~~~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a good change. This used to stack out, using more variance calculations removed the stack out, but I think have been hiding the error with incorrect results.

@Andarist
Copy link
Contributor Author

There's a bit more that you should handle, like propagating this "erased" type through indexed access operations, similarly to how wildcardType already works, and any other type constructor that wildcards propagate through.

Do u know what kind of tests I should use to verify that I'm moving in the right direction? I guess that for the most part I can heavily borrow from #43887 but since you mentioned that was a broader change... I'm not really able to tell quickly which parts are borrowable and which ones are not 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Waiting on author
Development

Successfully merging this pull request may close these issues.

4 participants