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>
            );
        }
    }
  • 相关阅读:
    1211.zuoye
    hw.python 鹿宏扬
    1206 python 鹿宏扬
    linux基础笔记
    Python20181204
    python1819 鹿宏扬 linux基础笔记
    [Kotlin]Spring Boot 使用thinJar打包找不到manifest问题
    Spring Boot设置默认返回UTF-8
    Go实现上传下载功能
    Flutter(二)Form Validating(表单验证)
  • 原文地址:https://www.cnblogs.com/ayseeing/p/14238567.html
Copyright © 2011-2022 走看看