typed-ember / glint

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

A keyword-only modifier does not type-check when used with the `modifier` helper #719

Open boris-petrov opened 5 months ago

boris-petrov commented 5 months ago
import { typeTest } from '@glint/type-test';
import { hbs } from 'ember-cli-htmlbars';
import { modifier } from 'ember-modifier';

interface Signature {
  Element: HTMLElement;
  Args: {
    Named: {
      block?: ScrollLogicalPosition;
    };
  };
}

typeTest(
  {
    mod: modifier<Signature>(() => {}),
  },
  hbs`
    <div {{(if true (modifier this.mod block="nearest"))}}></div>
  `,
);

There is an error on the modifier call - Property '[NamedArgs]' is missing in type 'HTMLDivElement' but required in type 'NamedArgsMarker'. Making block a mandatory parameter (i.e. removing the ?) fixes the issue and then it works. But I don't want it mandatory. :smile: Also, using (modifier this.mod (hash block="nearest")) makes it compile fine but that has a different meaning at runtime so it's also not what I want.

Somewhat similar to https://github.com/typed-ember/glint/issues/86 and https://github.com/typed-ember/glint/discussions/627.