typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
110 stars 51 forks source link

Difference between using `component` and assigning it via `let` #556

Closed boris-petrov closed 1 year ago

boris-petrov commented 1 year ago
import type { ComponentLike } from '@glint/template';
import { typeTest } from '@glint/type-test';

typeTest(
  {
    x: null as any as ComponentLike<{ Args: { required: number } }>,
  },
  hbs`
    {{! @glint-expect-error }}
    {{component this.x}}

    {{#let (component this.x) as |Component|}}
      {{! @glint-expect-error }}
      <Component />
    {{/let}}
  `,
);

The first @glint-expect-error fails, that is, there is no error on the following line, even though the required parameter is not passed. The <Component /> line is correctly marked as problematic.

I was under the impression that the first case will never be supported and one should always use let with component. If so, it would be nice to have an error message when using component in non-block form (as there seems to be an error when using it in a block form). If both ways are supposed to work, then this is a bug.

This is what I mentioned in this comment.

cc @dfreeman

dfreeman commented 1 year ago

Thanks for writing this up! We definitely did have a check for this at some point; it appears to have gotten lost in the refactoring.