承认我有这样的功能
const createPerson = () => ({ firstName: 'John', lastName: 'Doe' })
Run Code Online (Sandbox Code Playgroud)
如果在声明之前没有声明接口或类型,我怎么能createPerson得到返回值类型?
像这样的东西:
type Person = typeof createPerson()
Run Code Online (Sandbox Code Playgroud)
我有一个Redux容器,它将状态和调度操作映射到组件的props.
import { CounterState } from 'reducers/counter'
// ... Here I also defined MappedState and mapStateToProps
// The interface I would like to remove
interface MappedDispatch {
increment: () => any
}
// And get the return value type of this function
const mapDispatchToProps =
(dispatch: Dispatch<State>): MappedDispatch => ({
increment: () => …Run Code Online (Sandbox Code Playgroud) typescript ×1