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

Fix Signature handling for unions and generics #390

Merged
merged 2 commits into from Apr 1, 2022
Merged

Conversation

chriskrycho
Copy link
Contributor

When using a keyof type to check whether the type parameter for Glimmer Component is a Signature or the classic Args-only type, if we do not force TS to distribute over union types, it resolves the keyof check for union types with no shared members as never, and never extends <anything> is always true. This in turn meant that for all such unions, as well as for cases where users were providing generic types which could then be further extended in their own subclasses.

Accordingly, introduce the standard technique TypeScript provides for opting into distributivity: conditional types are documented to support exactly this.

The first commit adds failing tests covering this; the second implements the fix.

When using a `keyof` type to check whether the type parameter for
Glimmer Component is a `Signature` or the classic `Args`-only type, if
we do not force TS to distribute over union types, it resolves the
`keyof` check for union types with no shared members as `never`, and
`never extends <anything>` is always true. This in turn meant that for
all such unions, as well as for cases where users were providing generic
types which could then be further extended in their own subclasses.

Accordingly, introduce the standard technique TypeScript provides for
opting into distributivity: conditional types are documented to support
exactly this.
@chadhietala chadhietala merged commit 26e3523 into v1.x Apr 1, 2022
@chadhietala chadhietala deleted the bugfix-signature branch April 1, 2022 18:03
chriskrycho added a commit to ember-modifier/ember-modifier that referenced this pull request Apr 1, 2022
This is basically testing that the types supplied here do not have the
problem fixed by glimmerjs/glimmer.js#390. Here, we do not have that
issue, but the tests will also make sure we don't accidentally
*introduce* that issue, either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants