Skip to content

Generic types with HelperLike #542

Answered by chriskrycho
swastik asked this question in Q&A
Discussion options

You must be logged in to vote

Good question! I would write this roughly like this (off the top of my head, so I cannot promise this is exactly right, but it's directionally correct):

declare function or<T extends any[]>(...params: T): T[number];

declare module '@glint/environment-ember-loose/registry' {
  export default interface Registry {
    or: typeof or;
  }
}

Or, with a class-based helper:

import type Helper from '@ember/component/helper';

declare class OrHelper<T extends any[]> extends Helper<{
  Args: {
    Positional: T;
  };
  Return: T[number];
}> {
  compute(positional: T): T[number];
}

declare module '@glint/environment-ember-loose/registry' {
  export default interface Registry {
    or: typeof OrHelper;

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by chriskrycho
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #540 on March 14, 2023 00:17.