I
I
Incold2022-02-17 16:13:36
typescript
Incold, 2022-02-17 16:13:36

Why doesn't the [key: string]: any construct work?

Faced the problem of component typing.

Example: https://www.typescriptlang.org/play?#code/JYWwDg9g...

The task is that when passing a component to Pagination, the passed component must receive one data prop, and the rest is optional (and no matter what type) .

But despite the design[key: string]: any

type ComponentProps<T> = {
  data: T[];
  [key: string]: any;
};

ts file keeps asking for the full prop enum of the component and I get the error:

Type 'PropsWithChildren<ComponentProps>' is missing the following properties from type 'CompProps': x, y

Why does this error occur and how to fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question