zoukankan      html  css  js  c++  java
  • TS 作为表达式调用时,无法解析类修饰器的签名

    今天在搭建react项目的时候,遇到ts提示错误,如:

    代码:

    import concatRedux from '@utils/concatRedux'
    
    interface IProps extends IConnectProps {}
    interface IState { }
    
    @concatRedux('/home', 'HomeStore', ['fetchHome'])
    export default class Home extends React.Component<IProps, IState> {
        render() {
            return (
                <div className="page_test">
                    test
                </div>
            );
        }
    }

    报错如下:

    Unable to resolve signature of class decorator when called as an expression.

    Type 'ConnectedComponent<any, any>' is not assignable to type 'typeof Home'.

      Type 'NamedExoticComponent<any> & NonReactStatics<any, {}> & { WrappedComponent: any; }' provides no match for the signature 'new (props: IProps | Readonly<IProps>): Home'. TS1238

    解决方案:将 concatRedux 重命名可以绕过这个错误,如:

    import concatRedux from '@utils/concatRedux'
    
    interface IProps extends IConnectProps {}
    interface IState { }
    
    const concatReduxs: Function = concatRedux;
    
    @concatReduxs('/home', 'HomeStore', ['fetchHome'])
    export default class Home extends React.Component<IProps, IState> {
        render() {
            return (
                <div className="page_test">
                    test
                </div>
            );
        }
    }
  • 相关阅读:
    js闭包
    python切片 []取值操作符
    python with语句
    python鸭子类型(duck type)
    python编码规范
    python @property使用详解
    python __slots__使用详解
    Python面向对象编程
    ifconfig命令详解
    5、Cocos2dx 3.0游戏开发找小三之測试例子简单介绍及小结
  • 原文地址:https://www.cnblogs.com/ayseeing/p/14238567.html
Copyright © 2011-2022 走看看