Skip to content

Commit

Permalink
Merge pull request #647 from lukasnys/docs-template-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman authored Nov 7, 2023
2 parents 55a110e + 500a639 commit 52fde5b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Rendering Tests](ember/rendering-tests.md)
* [Using Addons](ember/using-addons.md)
* [Authoring Addons](ember/authoring-addons.md)
* [Template Imports](ember/template-imports.md)
* [GlimmerX](using-glint/glimmerx/README.md)
* [Installation](glimmerx/installation.md)
* [Component Signatures](glimmerx/component-signatures.md)
Expand Down
28 changes: 4 additions & 24 deletions docs/ember/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,13 @@ npm install -D @glint/core @glint/template @glint/environment-ember-loose

{% endcode %}

<details>
{% hint style="info" %}

<summary>Using ember-template-imports?</summary>
Using `ember-template-imports`? See [Ember: Template Imports][etii] for additional installation steps.

If you are using `ember-template-imports` in your project, you also need to install the `@glint/environment-ember-template-imports` package and configure it in `tsconfig.json` under `glint.environment`:
[etii]: ../ember/template-imports.md#installation

{% code title="tsconfig.json" %}
```json
{
"compilerOptions": { /* ... */ },
"glint": {
"environment": [
"ember-loose",
"ember-template-imports",
]
}
}
```
{% endcode %}

</details>
{% endhint %}

Note that, by default, Glint will assume you want it to analyze all templates in the codebase that are covered by your `tsconfig.json`. To ignore any type errors up front so that you can incrementally migrate your project to typesafe templates, consider using [the `auto-glint-nocheck` script](https://github.com/typed-ember/glint/tree/main/packages/scripts#auto-glint-nocheck) to add [`@glint-nocheck` comments](../directives.md#glint-nocheck) to your existing templates that would produce errors.

Expand All @@ -65,12 +51,6 @@ Finally, ensure you've added the following statement somewhere in your project's
import '@glint/environment-ember-loose';
```

If using `ember-template-imports`, add a corresponding line for that environment as well:

```typescript
import '@glint/environment-ember-template-imports';
```

You may also choose to disable TypeScript's "unused symbol" warnings in your editor, since Glint will flag any symbols that are actually unused, while `tsserver` won't understand any symbol usage that only occurs in templates.

{% hint style="info" %}
Expand Down
73 changes: 73 additions & 0 deletions docs/ember/template-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
When adding Glint to an Ember project with `ember-template-imports` installed, there are a few additional things to consider.

## Installation

In addition to the `@glint/core`, `@glint/template` and `@glint/environment-ember-loose` packages, you also need to install the `@glint/environment-ember-template-imports` package and configure it in `tsconfig.json` under `glint.environment`:

{% tabs %}
{% tab title="Yarn" %}

```sh
yarn add --dev @glint/core @glint/template @glint/environment-ember-loose @glint/environment-ember-template-imports
```

{% endtab %}
{% tab title="npm" %}

```sh
npm install -D @glint/core @glint/template @glint/environment-ember-loose @glint/environment-ember-template-imports
```

{% endtab %}
{% endtabs %}

{% code title="tsconfig.json" %}

```javascript
{
"compilerOptions": { /* ... */ },
"glint": {
"environment": [
"ember-loose",
"ember-template-imports",
]
}
}
```

Additionally, ensure you've added the following statement somewhere in your project's source files or ambient type declarations:

```typescript
import '@glint/environment-ember-template-imports';
```

{% endcode %}

## Template-Only Components

When using `ember-template-imports`, you can declare the type of a `<template>` component using the `TOC` type:

{% code title="app/components/shout.gts %}

```typescript
import type { TOC } From '@ember/component/template-only';

interface ShoutSignature {
Element: HTMLDivElement;
Args: { message: string };
Blocks: {
default: [shoutedMessage: string];
};
}

const louderPlease = (message: string) => message.toUpperCase();

const Shout: TOC<ShoutSignature> = <template>
<div ...attributes>
{{yield (louderPlease @message)}}
</div>
</template>;
export default Shout;
```
{% endcode %}
7 changes: 7 additions & 0 deletions docs/ember/template-only-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ declare module '@glint/environment-ember-loose/registry' {

Note that the runtime content of this module (effectively `export default templateOnlyComponent();`) is exactly what Ember generates at build time when creating a backing module for a template-only component.

{% hint style="info" %}

Using `ember-template-imports`? See [Ember: Template Imports][etitoc] on how to declare types for a `<template>`-only component.

[etitoc]: ../ember/template-imports.md#template-only-components
{% endhint %}

Due to the way TypeScript works, it's not possible to have a generic signature for template-only components:

```typescript
Expand Down

0 comments on commit 52fde5b

Please sign in to comment.