I
I
IDONTSUDO2020-05-22 23:36:00
typescript
IDONTSUDO, 2020-05-22 23:36:00

TS React children state?

There is such a beautiful error, TS does not allow me to dynamically shove data into the state. That is, I need to pass data from parent to child, and pass the function that is provided below. Which component would use. To pass the data back. Data is a lot of state big. How to deal with TS in this case?
PS. "noImplicitAny": false flag enabled

public ChildrenSetState = (name:any,value:any) => {
          this.setState({[name]:value})
  }


[Ошибка]: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type 'State

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IDONTSUDO, 2020-05-22
@IDONTSUDO

// @ts-ignore
Set at the beginning of the file, but it's ridiculous.

D
Dmitry Belyaev, 2020-05-23
@bingo347

Or it is normal to type this function (why do you need ts at all if you write any?), or plug the type field into the state type[k: any]: any

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question