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

TypeScript Support #14

Closed
josemarluedke opened this issue Mar 21, 2021 · 3 comments
Closed

TypeScript Support #14

josemarluedke opened this issue Mar 21, 2021 · 3 comments

Comments

@josemarluedke
Copy link

josemarluedke commented Mar 21, 2021

Currently, we cannot use the hbs template literal with TypeScript files.

The problem is that TS removes unused imports, so all the components/helpers/modifiers that are imported for a given component gets removed, resulting in error due to not having these definitions.

As a workaround, we can fakely pass the scope variables. NOTE: They don't do anything rather than making TS keep the imports.

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { hbs } from 'ember-template-imports';
import { Button } from './other/bla';
import { on } from '@ember/modifier';

export default class Hello extends Component {
  name = 'world';

  @action
  doSomething() {
    console.log('action called');
  }

  static template = hbs(
    `
    <span>Hello, {{this.name}}!</span>
    <Button class="button" {{on "click" this.doSomething}}>Cool</Button>
  `,
    { scope: { Button, on } }
  );
}

While this workaround works, this is not ideal, therefore we should have better support for typescript users.

@knownasilya
Copy link

knownasilya commented Mar 26, 2021

Does .gts work?

Doesn't seem so, says Could not find module 'ember-flow/components/flow-editor' imported from 'dummy/components/flow-editor'

Also if I try the hbs method, I get this:

Build Error (broccoli-persistent-filter:Babel > [Babel: ember-flow]) in ember-flow/components/flow-editor.ts

/Users/iradchenko/maintained/ember-flow/ember-flow/components/flow-editor.ts: Identifier 'hbs' has already been declared (10:9)

   8 | import { throttle } from '@ember/runloop';
   9 | // @ts-ignore
> 10 | import { hbs } from 'ember-template-imports';
     |          ^
  11 |
  12 | interface Args {}

This is in an addon. If I rename it, it works:

import { hbs as tpl } from 'ember-template-imports';

@chriskrycho
Copy link
Collaborator

This will likely need to be solved via Glint, both the LS and the CLI integration, which we can teach how to understand these files (and indeed: it already works with this basic format courtesy of glimmer-experimental).

@NullVoxPopuli
Copy link
Collaborator

Closing per RFC 779, and v4 of ETI. Hbs isn't supported anymore. Thank you for reporting!

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

No branches or pull requests

4 participants