我试图弄清楚如何从现有的Typescript函数中获取类型并使用它来定义接口.我正在研究React项目,我想将action creator(函数)传递给Props接口,然后传递给React Component as Component<Props, State>.
示例动作创建者:
export function myFunction(foo: string = "bar") {
return {
type: "EXAMPLE_ACTION",
payload: foo,
}
}
Run Code Online (Sandbox Code Playgroud)
示例组件:
import React, { Component } from 'react'
import { connect } from "react-redux"
import { myFunction } from "actions"
export interface Props {
// This is what I'm trying to and and it ends up in ts error
myFunc: myFunction
}
class SomeComponent extends Component<Props, {}> {
render() {
return (
<div> …Run Code Online (Sandbox Code Playgroud)