Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

tsx interface定义中的语法问题

请教一下,在 ionic-react 示例中有如下的一段定义 connect 功能的代码块

/src/data/connect.tsx line:6

interface ConnectParams<TOwnProps, TStateProps, TDispatchProps> {
  mapStateToProps?: (state: AppState, props: TOwnProps) => TStateProps,
  mapDispatchToProps?: TDispatchProps,
  component: React.ComponentType<any>
};

export function connect<TOwnProps = any, TStateProps = any, TDispatchProps = any>({ mapStateToProps = () => ({} as TStateProps), mapDispatchToProps = {} as TDispatchProps, component }: ConnectParams<TOwnProps, TStateProps, TDispatchProps>): React.FunctionComponent<TOwnProps> {
    // ...
}

有几个不太懂的地方

  1. interface 定义中接 <TOwnProps, TStateProps, TDispatchProps> 的写法在各文档中都未找到相关资料,请教下是什么意思?
  2. export function connect 后的参数类型限制似乎与形参未能对应上,该怎么理解?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

1.不是范型吗?
2.范型默认类型
不是很明白你的意思


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...