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

fix(redux-actions): createAction<Payload>(actionType: string) is incorrect. #16643

Merged
1 commit merged into from
Jun 7, 2017

Conversation

meowtec
Copy link
Contributor

@meowtec meowtec commented May 19, 2017

createAction(actionType: string) and createAction(actionType: string) is incorrect

also see #15697

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

@dt-bot
Copy link
Member

dt-bot commented May 19, 2017

types/redux-actions/index.d.ts

to authors (@jaysoo @alexgorbatchev). Could you review this PR?
👍 or 👎?

Checklist

  • pass the Travis CI test?

@@ -85,7 +89,7 @@ export function createAction<Payload, Arg1, Arg2, Arg3, Arg4>(

export function createAction<Payload>(
actionType: string
): ActionFunctionAny<Action<Payload>>;
): ActionFunction1<Payload, Action<Payload>>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be right -- now there are 2 single-argument and they return different results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find a similar example:

  public static create<T0>(): Dispatcher1<T0>;
  public static create<T0, T1>(): Dispatcher2<T0, T1>;
  public static create<T0, T1, T2>(): Dispatcher3<T0, T1, T2>;

from microsoft/TypeScript#1024 (comment) .

And I also test my new definition:

const act0 = ReduxActions.createAction('ACTION0')
const act1 = ReduxActions.createAction<string>('ACTION1')

act0().payload // void
act1('hello').payload // string

It seem to be expected.

@ghost
Copy link

ghost commented Jun 7, 2017

Thanks!

@ghost ghost merged commit 887a4e8 into DefinitelyTyped:master Jun 7, 2017
@meowtec
Copy link
Contributor Author

meowtec commented Jun 8, 2017

Maybe I have made a mistake (break change).

Because now the code below will get an error:

createAction('ACTION')('payload') // error
// createAction<string>('ACTION')('payload') // ok

I think it will be better if we define like this:

export function createAction(
    actionType: string
): ActionFunctionAny<Action<any>>; // any instead of 0

or

export function createAction(
    actionType: string
): <T>(arg?: T) => Action<T>;

@ghost
Copy link

ghost commented Jun 8, 2017

Sound good, you can make a PR.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants