From 662e998e5bb2031dc10d60bc8d5393819030b423 Mon Sep 17 00:00:00 2001 From: Alexander Lang Date: Fri, 23 Dec 2022 09:42:04 +0100 Subject: [PATCH] Update to new Glint addon best practices The Glint docs now recommend to export the Registry, see https://typed-ember.gitbook.io/glint/using-glint/ember/authoring-addons --- README.md | 24 +++++++++++++++++++ .../addon/template-registry.d.ts | 6 +++++ .../helpers/svg-jar.d.ts => addon/types.ts} | 0 packages/ember-svg-jar/types/glint.d.ts | 8 ------- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 packages/ember-svg-jar/addon/template-registry.d.ts rename packages/ember-svg-jar/{types/helpers/svg-jar.d.ts => addon/types.ts} (100%) delete mode 100644 packages/ember-svg-jar/types/glint.d.ts diff --git a/README.md b/README.md index f6266e7..d90cf0c 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,30 @@ var app = new EmberApp(defaults, { [Click here for more configuration options](#configuration) +### TypeScript usage + +The `svg-jar` helper 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 EmberSvgJarRegistry from 'ember-svg-jar/template-registry'; + +declare module '@glint/environment-ember-loose/registry' { + export default interface Registry + extends EmberSvgJarRegistry /* other addon registries */ { + // local entries + } +} +``` + +Should you want to manage the registry by yourself, then omit this import, and instead add the entries in your app by explicitly importing the types of the helper from this addon. + +> Note that 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! + ### Usage in an addon Using `ember-svg-jar` in an addon is the same as in an app, except that in the `package.json` diff --git a/packages/ember-svg-jar/addon/template-registry.d.ts b/packages/ember-svg-jar/addon/template-registry.d.ts new file mode 100644 index 0000000..5df6b34 --- /dev/null +++ b/packages/ember-svg-jar/addon/template-registry.d.ts @@ -0,0 +1,6 @@ +import type SvgJar from './types'; + +export default interface EmberSvgJarRegistry { + 'svg-jar': typeof SvgJar; + svgJar: typeof SvgJar; +} diff --git a/packages/ember-svg-jar/types/helpers/svg-jar.d.ts b/packages/ember-svg-jar/addon/types.ts similarity index 100% rename from packages/ember-svg-jar/types/helpers/svg-jar.d.ts rename to packages/ember-svg-jar/addon/types.ts diff --git a/packages/ember-svg-jar/types/glint.d.ts b/packages/ember-svg-jar/types/glint.d.ts deleted file mode 100644 index fad897e..0000000 --- a/packages/ember-svg-jar/types/glint.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type SvgJar from './helpers/svg-jar'; - -declare module '@glint/environment-ember-loose/registry' { - export default interface Registry { - 'svg-jar': typeof SvgJar; - svgJar: typeof SvgJar; - } -}