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> ); } }