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>
            );
        }
    }
  • 相关阅读:
    re | [SWPU2019]ReverseMe
    wp | re | 2020“巅峰极客”网络安全技能挑战赛
    re | [CFI-CTF 2018]IntroToPE
    re | [FlareOn1]Bob Doge
    re | [ACTF新生赛2020]SoulLike
    re | [GKCTF2020]Chelly's identity
    ospf配置与ofps选举DR/BDR
    静态路由的配置
    配置三层交换机实现vlan间通信
    hybrid接口
  • 原文地址:https://www.cnblogs.com/ayseeing/p/14238567.html
Copyright © 2011-2022 走看看