Skip to content

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

Closed
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/variance-measurement-type-alias-generic-fn
Closed

Fixed some variance measurements in type aliases of generic functions#54866
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:fix/variance-measurement-type-alias-generic-fn

Conversation

@Andarist
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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 😅

@typescript-bot
Copy link
Copy Markdown
Collaborator

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:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

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: Done

Development

Successfully merging this pull request may close these issues.

6 participants