taro 2.2.11 @connect ts提示怎么解决?
-
-
@connect() 没法提示,这是Typescript本身的限制,官方issue里有写。装饰器目前在TS不会有任何的提示,这就是我很少用装饰器的原因
您可以这么做:
type Props = ReturnType<typeof mapStateToProps>; class App extends Component<Props> { render() { ... } } const mapStateToProps = (store) => { return { data: store.xx, }; };
或者使用React Hooks,就不需要这些东西。
import React, { FC } from 'react'; import { useSelector } from 'react-redux'; const App: FC = () => { const data = useSelector((store) => store.xx); return <Text></Text>; };
当然也推荐Redux深度封装的库,只需关心业务,提高您2-3倍开发效率:https://github.com/redux-model/redux-model