M
M
Merser19052020-02-03 11:06:56
JavaScript
Merser1905, 2020-02-03 11:06:56

Map typing in react typescript?

Good day to all. There was such a problem. I'm trying to make a universal component for the text, which can be used both for headings and for plain text. I make a map of the correspondence so that, depending on the required prop type, the required styled component is drawn. I ask for help with typing, I don’t understand how to type an object with a map so that the keys are clearly the values ​​from the enum, but the values ​​of the function that the component returns. I’ve been familiar with react ts not so long ago, so I’m asking for help) Thanks in advance for the answer, I’ve screened all the pieces of the code. This is the entire component.
5e37d3e43d559956082907.png
5e37d3eec89f8787892660.png
5e37d3f698c8a018785836.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-02-03
@Merser1905

type X = {[k in TypeText]: () => {}}
I would substitute your types, but they are poorly copied from the picture, and I'm too lazy to type them with my hands

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question