From e53e35158f87b27dde7d20fdabcfe43a725a9ae2 Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Fri, 17 Feb 2023 01:42:33 +0000 Subject: [PATCH] Add Glint template registry for local-class helper --- README.md | 21 +++++++++++++++++++ .../ember-css-modules/template-registry.d.ts | 15 +++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 packages/ember-css-modules/template-registry.d.ts diff --git a/README.md b/README.md index 751db06..2044fc8 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,27 @@ export default Ember.Controller.extend({ }); ``` +### Glint usage + +Helper `{{local-class}}` 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 EmberCssModulesRegistry from 'ember-css-modules/template-registry'; + +declare module '@glint/environment-ember-loose/registry' { + export default interface Registry extends EmberCssModulesRegistry, /* other addon registries */ { + // local entries + } +} +``` + ## Usage in Addons You can also use ember-css-modules in addons that expose components to their consuming application. To do this you'll need to move `ember-css-modules` out of `devDependencies` and into `dependencies` in your addon's `package.json` ([see issue #8](https://github.com/salsify/ember-css-modules/issues/8)). diff --git a/packages/ember-css-modules/template-registry.d.ts b/packages/ember-css-modules/template-registry.d.ts new file mode 100644 index 0000000..e0a38ce --- /dev/null +++ b/packages/ember-css-modules/template-registry.d.ts @@ -0,0 +1,15 @@ +import type { HelperLike } from '@glint/template'; + +interface Signature { + Args: { + Positional: [string]; + Named: { + from?: string | undefined; + }; + }; + Return: string; +} + +export default interface EmberCssModulesRegistry { + 'local-class': HelperLike; +}