Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ that accepts "contextual components" as arguments:
{{!-- ...or more directly... --}}
<@tag class="my-tag">hello world!</@tag>
```
### Glint usage

Helpers `{{element}}` has proper [Glint](https://github.com/typed-ember/glint) types,
which allow you when using TypeScript to get strict type checking in your templates.

Unless you are using [strict mode](http://emberjs.github.io/rfcs/0496-handlebars-strict-mode.html) templates
(via [first class component templates](http://emberjs.github.io/rfcs/0779-first-class-component-templates.html)),
you need to import the addon's Glint template registry and extend your app's registry declaration
as described in the [Using Addons](https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons#using-glint-enabled-addons) documentation:

```ts
import '@glint/environment-ember-loose';
import type EmberElementHelperRegistry from 'ember-element-helper/template-registry';
declare module '@glint/environment-ember-loose/registry' {
export default interface Registry extends EmberElementHelperRegistry, /* other addon registries */ {
// local entries
}
}
```

> **Note:** Glint itself is still under active development, and as such breaking changes might occur.
> Therefore, Glint support by this addon is also considered experimental, and not covered by our SemVer contract!


Contributing
------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions ember-element-helper/src/helpers/element.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Helper from '@ember/component/helper';
import type { ComponentReturn } from '@glint/template/-private/integration';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on private types for this is (a) dangerous, but (b) fortunately unnecessary 🙂

You can do this with public API and actually get the correct typing for it as well by defining the signature as something like:

export interface ElementHelperSignature<T extends string> {
  Args: {
    Positional: [name: T];
  };
  Return: ComponentLike<{
    Element: 
      T extends keyof HTMLElementTagNameMap
        ? HTMLElementTagNameMap[T]
        : Element;
    Blocks: { default: [] };
  }>;
}

export default class ElementHelper<T extends string> extends Helper<ElementHelperSignature<T>> {}


interface ElementHelperSignature {
Args: {
Positional: [tagName: keyof HTMLElementTagNameMap];
};
Return: (...positional: unknown[]) => ComponentReturn<any, any>;
}

export default class ElementHelper extends Helper<ElementHelperSignature> {}
5 changes: 5 additions & 0 deletions ember-element-helper/template-registry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type ElementHelper from "./src/helpers/element";

export default interface EmberElementHelperRegistry {
'element': typeof ElementHelper;
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
"yarn": "1.22.17"
},
"devDependencies": {
"@glint/template": "^1.0.0-beta.3",
"concurrently": "^7.2.2"
},
"peerDependencies": {
"@glint/template": "^1.0.0-beta.3"
},
"resolutions": {
"eslint-plugin-decorator-position": "^4.0.0"
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,11 @@
"@glimmer/interfaces" "^0.42.2"
"@glimmer/util" "^0.42.2"

"@glint/template@1.0.0-beta.3":
version "1.0.0-beta.3"
resolved "https://registry.yarnpkg.com/@glint/template/-/template-1.0.0-beta.3.tgz#5866c0ffc1d8273f2e9b2fd186b65f5d4e6dbc15"
integrity sha512-jxn4yGzNZ1A4NGzvjYht0NlVziHyzjj/rm4rGsP1mVUO2Dd/LHhhxR6NUlSw9MFDZ0fCinULVwQtAKQLEpIpPw==

"@handlebars/parser@~2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@handlebars/parser/-/parser-2.0.0.tgz#5e8b7298f31ff8f7b260e6b7363c7e9ceed7d9c5"
Expand Down