账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react + typescript 的时候,使用修饰器,编译报错?
    27
    0
    function dectest(target: any) {
        target.prototype.name = 'isfufeng'
    }
    
    @dectest
    export default class Home extends React.Component<Props, State> {
        constructor(props: any) {
            super(props)
        }
    }

    先是使用了这个往里面添加一个name类,但是编译时报错

    Module not found: Error: Can't resolve 'babel-runtime/core-js/reflect/metadata' in 'd:\allpro\reactdom\reactM\reactAdmin\src\components\home'

    后面又使用了 react-redux 的connect方法。

    作为表达式调用时,无法解析类修饰器的签名。
      不能将类型“ComponentClass<Pick<any, never>> & { WrappedComponent: ComponentType<any>; }”分配给类型“typeof Home”。
        不能将类型“Component<Pick<any, never>, ComponentState>”分配给类型“Home”。
          属性“componentDidMount”在类型“Component<Pick<any, never>, ComponentState>”中为可选,但在类型“Home”中为必选。

    在.babelrc里面添加了

    "plugins": [
            "react-hot-loader/babel",
            "transform-decorators-legacy",
            "transform-runtime",
            "transform-class-properties"
        ],

    有大神知道怎么解决嘛。

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部