相关线 。
如果界面如下:
export interface Dispatch<S> { <A extends Action>(action: A): A; }......显然没有使用S ,为什么会出现?
我注意到S在其他地方用于“商店”相关的东西,但如果它没有在这个界面中使用,我不认为它应该在那里。
Relevant line.
If the interface is as follows:
export interface Dispatch<S> { <A extends Action>(action: A): A; }...and S is clearly not used, then why is it there?
I notice that S is used elsewhere for "store" related things, but if it's not used in this interface, I don't think it should be there.
最满意答案
你是对的,就它本身而言似乎并没有多大意义。
我的猜测是他们已经完成它以确保在中间件中返回调度函数。
在像redux-thunk这样的中间件的情况下, 新的调度函数确实使用<S>参数,虽然我不确定如果在这种情况下默认值不重要。
Having state type parameter S allows middlewares be more accurate in typings. For example, thunk function takes a dispatch and a getState(): S, so without S it couldn't be well-typed. See the example of this here below https://github.com/Igorbek/redux/blob/ts-def-improv/test/typescript/dispatch.ts#L9-L16
Source
Credit goes to @Lucas for finding that source.
更多推荐
发布评论