From 7b3e39e09e496428d9d1764557f8f142fe8dad89 Mon Sep 17 00:00:00 2001 From: Jordan Hawker Date: Wed, 8 Jan 2025 14:44:03 -0800 Subject: [PATCH 1/2] Clarify typing for no arguments/blocks Update verbiage and add code example to make it clear how to handle scenarios where a component has no arguments or no block invocation --- docs/ember/component-signatures.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/ember/component-signatures.md b/docs/ember/component-signatures.md index 20215452c..9d47c78b3 100644 --- a/docs/ember/component-signatures.md +++ b/docs/ember/component-signatures.md @@ -13,8 +13,8 @@ compatible with the DOM element(s) they're ultimately attached to. If no `Elemen 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. +those blocks will receive. If your component does not support block invocation, omit the `Blocks` field altogether +to generate type errors when invoked 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. @@ -67,6 +67,32 @@ export default class SuperTable extends Component> {} {% endcode %} +{% code title="app/components/simple-hello.ts" %} + +```typescript +import Component from '@glimmer/component'; + +export interface SimpleHelloSignature { + // We have a `
` as our root element + Element: HTMLDivElement; + // We accept no arguments + Args: Record; + // We do not accept block form, so don't specify it in the signature +} + +export default class SimpleHello extends Component {} +``` + +{% endcode %} + +{% code title="app/components/simple-hello.hbs" %} + +```handlebars +
Hello World!
+``` + +{% endcode %} + ## Ember Components Since Ember components don't have `this.args`, it takes slightly more boilerplate to make them typesafe. From 2e1f8aebad82c9ce1559faf5f1826a2d7b217d4f Mon Sep 17 00:00:00 2001 From: Jordan Hawker Date: Wed, 8 Jan 2025 14:59:37 -0800 Subject: [PATCH 2/2] Remove args from code example --- docs/ember/component-signatures.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/ember/component-signatures.md b/docs/ember/component-signatures.md index 9d47c78b3..411668293 100644 --- a/docs/ember/component-signatures.md +++ b/docs/ember/component-signatures.md @@ -75,9 +75,7 @@ import Component from '@glimmer/component'; export interface SimpleHelloSignature { // We have a `
` as our root element Element: HTMLDivElement; - // We accept no arguments - Args: Record; - // We do not accept block form, so don't specify it in the signature + // We accept no arguments or block form, so don't specify them in the signature } export default class SimpleHello extends Component {}