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

Narrowing @namedArgs does not work, but narrowing this.args.namedArgs does work. (@X named args are not aliased to "this.args.X" internally) #715

Open
NullVoxPopuli opened this issue Mar 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Mar 19, 2024

This correctly narrows:

function isMulti(x: 'single' | 'multi' | undefined): x is 'multi' {
  return x === 'multi';
}

export class ToggleGroup<Value = any> extends Component<{
  Element: HTMLDivElement;
  Args: SingleSignature<Value>['Args'] | MultiSignature<Value>['Args'];
  Blocks: {
    default: [
      {
        Item: Item;
      },
    ];
  };
}> {
  <template>
    {{#if (isMulti this.args.type)}}
      <MultiToggleGroup @value={{this.args.value}} @onChange={{this.args.onChange}} ...attributes />
    {{else}}
      <SingleToggleGroup @value={{this.args.value}} @onChange={{this.args.onChange}} ...attributes />
    {{/if}}
  </template>
}

This does not:

function isMulti(x: 'single' | 'multi' | undefined): x is 'multi' {
  return x === 'multi';
}

export class ToggleGroup<Value = any> extends Component<{
  Element: HTMLDivElement;
  Args: SingleSignature<Value>['Args'] | MultiSignature<Value>['Args'];
  Blocks: {
    default: [
      {
        Item: Item;
      },
    ];
  };
}> {
  <template>
    {{#if (isMulti @type)}}
      <MultiToggleGroup @value={{@value}} @onChange={{@onChange}} ...attributes />
    {{else}}
      <SingleToggleGroup @value={{@value}} @onChange={{@onChange}} ...attributes />
    {{/if}}
  </template>
}

these should be equiv, but @namedArg syntax should be all that folks use, as it's consistent cross-component authoring format. this.args in templates is discouraged and Glint should not encourage it 😅

Here is a TSPlayground showing that what I want to do (and the this.args example) works in plain TS.

@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Mar 19, 2024
@NullVoxPopuli NullVoxPopuli changed the title Narrowing @namedArgs does not work, but narrowing this.args.namedArgs does work. Narrowing @namedArgs does not work, but narrowing this.args.namedArgs does work. (@X named args are not aliased to "this.args.X" internally) Mar 19, 2024
@NullVoxPopuli
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant