типов?
// TS2339: Property 'onChange' does not exist on type 'ClassAttributes & InputHTMLAttributes '.
export const Input: React.FC<JSX.IntrinsicElements['input']> = ({ value, onChange }) => {
return <input type={'text'} onChange={onChange} value={value} />;
};
import React from 'react'; export const Input: React.FC<React.InputHTMLAttributes<HTMLInputElement>> = ({ value, onChange }) => { return <input type="text" onChange={onChange} value={value} />; };
Только теперь другая ошибка: export interface InputProps extends InputHTMLAttributes<HTMLInputElement> { onChange?: (e: ChangeEvent<HTMLInputElement>) => void; } export const Input: React.FC<InputProps> = ({ value, onChange, specialProp }) => { // TS2322: Type '{ type: "text"; onChange: ((e: ChangeEvent<HTMLInputElement>) => void) | undefined; value: string | number | readonly string[] | undefined; }' is not assignable to type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. Property 'onChange' does not exist on type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. return <input type={'text'} onChange={onChange} value={value} />; };
import React, { ChangeEvent } from 'react'; interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> { onChange: (event: ChangeEvent<HTMLInputElement>) => void; } export const Input: React.FC<InputProps> = ({ value, onChange }) => { return <input type="text" onChange={onChange} value={value} />; };
у меня так, у тебя также? interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> { onChange: (event: ChangeEvent<HTMLInputElement>) => void; } export const Input: React.FC<InputProps> = ({ value, onChange }) => { // Property 'onChange' does not exist on type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. return <input type={'text'} onChange={onChange} value={value} />; };
было "@types/react": "18.0.28", стало "@types/react": "18.2.6", почему то onChange в 18.0.28 версии нет)
Обсуждают сегодня