如何修复绑定元素 'children' 隐式具有 'any' type.ts(7031)? [英] How to fix Binding element 'children' implicitly has an 'any' type.ts(7031)?

查看:824
本文介绍了如何修复绑定元素 'children' 隐式具有 'any' type.ts(7031)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里缺少一些验证如何添加类型验证?出现错误元素‘children’隐式具有‘any’类型".

I'm missing something here with the validation how to add types validation? Having error "element 'children' implicitly has an 'any' type".

import * as React from 'react';
import Button from './Styles';

const Button1 = ({ children, ...props }) => (
  <Button {...props}>{children}</Button>
);

Button1.propTypes = {};

export default Button1;

推荐答案

是的,您缺少整个 Props 的类型,这意味着 typescript 将其视为 any 并且您的 ts 规则不允许它.

Yes you are missing a type for Props as whole, which means typescript sees it as any and your ts rules dont allow it.

你必须输入你的道具:

import React, { FC } from "react";

interface Props {
    // any props that come into the component
}

const Button1: FC<Props> = ({ children, ...props }) => (
    <Button {...props}>{children}</Button>
);

这篇关于如何修复绑定元素 'children' 隐式具有 'any' type.ts(7031)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆