Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caveats to using RouteTemplate as decorator? #13

Open
IgnaceMaes opened this issue Aug 15, 2024 · 0 comments
Open

Caveats to using RouteTemplate as decorator? #13

IgnaceMaes opened this issue Aug 15, 2024 · 0 comments

Comments

@IgnaceMaes
Copy link
Contributor

Been very much enjoying using this addon, thanks for creating this!

The documentation in the Readme only documents calling RouteTemplate in the function form. However, I've been using it as decorator and it's been working great. I wonder if this should be documented?

Decorator usage

Example:

// app/templates/index.gjs
import RouteTemplate from 'ember-route-template';
import Component from '@glimmer/component';

// eslint-disable-next-line ember/no-empty-glimmer-component-classes
@RouteTemplate
export default class IndexTemplate extends Component {
  <template>
    Hello {{@model}}!
  </template>
}

I like that it resembles a regular component definition greatly. The downside is that it doesn't work for template-only components, though. In this example it's just a simple template wrapped in the backing class, but that does trigger the ES Lint warning.

TypeScript

TypeScript works, but complains on the return type:

Decorator function return type 'TemplateFactory' is not assignable to type 'void | typeof IndexTemplate'.
// app/templates/index.gts
import RouteTemplate from 'ember-route-template';
import Component from '@ember/component';

interface IndexTemplateSignature {
  Args: {
    model: string;
  }
}

@RouteTemplate
export default class IndexTemplate extends Component<IndexTemplateSignature> {
  <template>
    Hello {{@model}}!
  </template>
}

A hacky patch can be achieved by just adding an override that returns void:

declare module 'ember-route-template' {
  export default function RouteTemplate(Component: object): void;
}

Now TypeScript is happy 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant