Component Signatures
Since the implementation of RFC 748, Glimmer and Ember components accept a Signature
type parameter as part of their definition. This parameter is expected to be an object type with (up to) three members: Args
, Element
and Blocks
.
Args
represents the arguments your component accepts. Typically this will be an object type mapping the names of your args to their expected type. If no Args
key is specified, it will be a type error to pass any arguments to your component.
The Element
field declares what type of element(s), if any, the component applies its passed ...attributes
to. This is often the component's root element. Tracking this type ensures any modifiers used on your component will be compatible with the DOM element(s) they're ultimately attached to. If no Element
is specified, it will be a type error to set any HTML attributes or modifiers when invoking your component.
The Blocks
field specifies the names of any blocks the component yields to, as well as the type of any parameter(s) those blocks will receive. If no Blocks
key is specified, it will be a type error to invoke your component in block form.
Note that the inverse
block is an alias for else
. These should be defined in Blocks
as else
, though {{yield to="inverse"}}
will continue to work.
Glimmer Components
Ember Components
Since Ember components don't have this.args
, it takes slightly more boilerplate to make them typesafe.
Ember components also support positional arguments in their signature. Such usage is relatively rare, but components such as {{animated-if}}
do take advantage of it.
Positional args are specified as a Positional
tuple nested within Args
, the same way they are in helper and modifier signatures. You can also specify positional args with ComponentLike
types in this way.
Note that both Positional
args and the Element
type are not fully integrated with the string-based APIs on the @ember/component
base class. This means, for example, that there's no enforcement that tagName = 'table'
and Element: HTMLTableElement
are actually correlated to one another.
Last updated