Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow action to be typed with any #219

Merged
merged 2 commits into from
Jan 13, 2019
Merged

Conversation

laat
Copy link
Contributor

@laat laat commented Oct 9, 2018

By swapping the order of the calls, the Action param can be any. From #213 (comment)

@timdorr
Copy link
Member

timdorr commented Jan 13, 2019

Thanks!

@timdorr timdorr merged commit e546d62 into reduxjs:master Jan 13, 2019
@timdorr timdorr mentioned this pull request Sep 11, 2020
@zqran
Copy link

zqran commented Nov 16, 2021

I found that when writing code in VSCode, there is no clear type hint. Is it related to this?

The demo is as follows:
https://codesandbox.io/s/redux-thunk-ts-7ygmv?file=/src/index.ts

@laat
Copy link
Contributor Author

laat commented Nov 16, 2021

It's not related, there has been lots of changes since this commit.

I cannot reproduce your issue, however I get a ReferenceError: type is not defined, because the type variable is not defined.

@zqran
Copy link

zqran commented Nov 17, 2021

When you type the code, there will be no type hint for the type attribute

image

When I try to exchange the overload order, it will be prompted:

ThunkDispatch:Original type from redux-thunk v2.4.0:(no type hint)

export interface ThunkDispatch<State, ExtraThunkArg, BasicAction extends Action> extends Dispatch<BasicAction> {
    /** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */
    <ReturnType>(thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): ReturnType;
    /** A union of the other two overloads. This overload exists to work around a problem
     *  with TS inference ( see https://github.com/microsoft/TypeScript/issues/14107 )
     */
    <ReturnType, Action extends BasicAction>(action: Action | ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): Action | ReturnType;
}

Swapping the order of the calls:(type hint)

export interface ThunkDispatch<State, ExtraThunkArg, BasicAction extends Action> extends Dispatch<BasicAction> {
    /** A union of the other two overloads. This overload exists to work around a problem
     *  with TS inference ( see https://github.com/microsoft/TypeScript/issues/14107 )
     */
    <ReturnType, Action extends BasicAction>(action: Action | ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): Action | ReturnType;

    /** Accepts a thunk function, runs it, and returns whatever the thunk itself returns */
    <ReturnType>(thunkAction: ThunkAction<ReturnType, State, ExtraThunkArg, BasicAction>): ReturnType;
}

@markerikson
Copy link
Contributor

@zqran Please file a separate issue to discuss this - it sounds like a worthwhile topic, but it's unrelated to this issue.

@reduxjs reduxjs locked as resolved and limited conversation to collaborators Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants