Codesandbox .
Вот мой компонент ввода:
import styled from 'styled-components'
import React, { forwardRef } from 'react'
type Props = {
err: boolean
maxWidth: string
}
export const Input = forwardRef<HTMLInputElement, Props>(({ ...rest }, ref) => {
return <StyledInput {...rest} ref={ref} />
})
const StyledInput = styled.input<Props>``
Вот использование:
<Input name='password' type='password' autoComplete='password' required />
Почему имя дает мне ошибку (как я вижу, другие реквизиты тоже имеют ошибку):
Type '{ name: string; type: string; autoComplete: string; required: true; }' is not assignable to type 'IntrinsicAttributes & Props & RefAttributes<HTMLInputElement>'.
Property 'name' does not exist on type 'IntrinsicAttributes & Props & RefAttributes<HTMLInputElement>'.ts(2322)
Когда интерфейс реакции по умолчанию имеет этот реквизит:
interface HTMLInputElement extends HTMLElement {
name: string;
/**
* Gets or sets a string containing a regular expression that the user's input must match.
*/
}