Answer the question
In order to leave comments, you need to log in
How to properly declare a function?
type strORnum = string | number;
interface IUser {
name: string;
age: number;
}
type partialState = { [propName in keyof IUser]: strORnum };
interface IContext extends IUser {
setState?: (value: partialState) => void;
}
const changeHandle = (e: React.ChangeEvent<HTMLInputElement>): void => {
if (setState !== undefined) {
const {target: { name: nameProp, value }, } = e;
setState({ [nameProp]: nameProp === "name" ? value : Number(value) }); <--- Тут ошибка *
}
};
Текст ошибки
Argument of type '{ [x: string]: string | number; }' is not assignable to parameter of type 'partialState'.
Type '{ [x: string]: string | number; }' is missing the following properties from type 'partialState': name, age
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question