BenderIsGreat34
@BenderIsGreat34
junior front-end

Какой тип указать для children.current у TS?

const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, children: ReactNode): void => {
        if (children) {
            const {current}: HTMLUListElement = children;
            if (current) {
                current.scrollTop = list.current.scrollHeight;
            }
        }
    }
setTimeout(() => handleClick(e, props.children), 0);

сыпится ошибка на current:
TS2322: Type 'string | number | true | {} | ReactElement ReactElement Component)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal' is not assignable to type 'HTMLUListElement'. Type 'string' is not assignable to type 'HTMLUListElement'.
TS2339: Property 'current' does not exist on type 'HTMLUListElement'.


не понимаю как задать current значение HTMLUListElement
  • Вопрос задан
  • 80 просмотров
Пригласить эксперта
Ответы на вопрос 2
@Rerurk
С //@ts-ignore компилятор все равно ошибку дает?
Ответ написан
Aetae
@Aetae Куратор тега TypeScript
Тлен
Возможно ак:
const {current}: {current: HTMLUListElement} = children;

или так:
const current = children.current as HTMLUListElement;

Вы же задаёте тип не current, а всего объекта.

P.S. Про ts-ignore забудьте.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы