-
Notifications
You must be signed in to change notification settings - Fork 51
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
Figure out the shape of component type parameters #25
Comments
A related issue to this is the fact that it's currently not possible to write a typesafe class-based helper in a way that the typechecker deems valid. import Helper from '@ember/component/helper';
export default class ShoutHelper extends Helper<[string], {}, string> {
public compute([message]: [string]): string {
return message.toUpperCase();
}
} Because This is similar to the discrepancy we face with trying to rework One option may be to re-export values like |
@jamescdavis @chriskrycho this issue is a partial capture of the "Glimmer 2 type params" question we have as an action item |
Quick question: AFAICT from reading and thinking about this, even fixing the type params (and doing as enabled by #54) wouldn't help with the variance problem for the type of positional params, would it? |
Weirdly I think the problem is actually with the Really the ideal would be to incorporate the type params in the base class, because then the variance works out correctly based on their position of usage. For now, though, what I'm looking at doing is essentially this: interface Helper<T> extends Omit<EmberHelper, 'compute'> {
compute(positional: ..., named: ...): ...;
} This means an instance of this |
Currently,
@glimmer/component
looks something like this:This RFC suggests adding a second type parameter to capture the types of a component's yields, something like:
However, this may not scale well as we consider other information we could eventually want to encode, such as #21. Capturing the type of a template's root element would add a third type param, and if we decide to allow authors to explicitly specify valid attrs, that would be a fourth.
A class with four type parameters is already unwieldy, but it's especially so if not every parameter will always be specified. An author might never yield from their component, but still have
...attributes
applied to an element.Given that, a signature along these lines may be more ergonomic (and more amenable to future expansion as necessary):
However, there are some questions we need to answer:
{ arrgs: MyComponentArgs }
would be valid, just not useful)args
key in the type would be a breaking change for@glimmer/component
—how much trouble would that cause?The text was updated successfully, but these errors were encountered: