Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants