G
G
GF2020-10-31 17:14:58
JavaScript
GF, 2020-10-31 17:14:58

Generics in @Input?

Is it possible to use generics in inputs? From the fact that I googled all the solutions are too complicated. How do you type props for reusable components?
5f9d7159110c5768480607.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-10-31
@fomenkogregory

From the point of view of typescript, there are no inputs, these are ordinary public fields.
Generics As usual, a class defines a variable type and can be extended to fields.

class MyComponent<T> {
  @Input() prop: T;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question