Skip to content

Accepting generic component as an argument #560

Answered by dfreeman
vstefanovic97 asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately this is something that there isn't quite a direct way to express to TypeScript. Taking a slightly simpler example:

declare const ComponentA: ComponentLike<{
  Args: {
    name: string;
    age: number;
  };
}>;

interface MyComponentSignature<T extends typeof ComponentA> {
  Args: { item: T };
  Blocks: {
    default: [item: WithBoundArgs<T, 'name'>];
  };
}

The issue you're running into is that ComponentA isn't the only possible thing T could be there. A component that only accepted a numeric @age arg, or that didn't require any arguments at all, would be equally valid.

Note that this isn't in any way specific to Glint, and is just a general property of how TypeScript's str…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by vstefanovic97
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