Skip to content

Changing interface to type for ActionCreator<P> in 3.0-beta-2 #70

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

Closed
MistyKuu opened this issue Dec 19, 2018 · 12 comments
Closed

Changing interface to type for ActionCreator<P> in 3.0-beta-2 #70

MistyKuu opened this issue Dec 19, 2018 · 12 comments

Comments

@MistyKuu
Copy link

I'm currently using typescript-fsa version 2.5. I'm augmenting ActionCreator interface like this:

declare module "typescript-fsa" {
  export interface ActionCreator<P> {
    type: string;
    payloadType: P;
    match: (action: Fsa.AnyAction) => action is Action<P>;
    (payload: P, meta?: Meta): Action<P>;
  }
}

The reason I'm doing it is that I extended it with payloadType. In 3.0 I'm not able to do that since types in typescript cannot be augmented. Is there any reason why you decided to use type?

@quantuminformation
Copy link

is this lib still maintained?

@aikoven
Copy link
Owner

aikoven commented Mar 12, 2019

@quantuminformation Yes!

@MistyKuu That's because in 3.0 the ActionCreator type is composed of two types using intersection (&), which lets us use different signature when Payload type is void. However, with newer TypeScript versions this is no longer needed, because you can skip void parameters (see microsoft/TypeScript#27522).

There are a few other things I'd like to fix before releasing 3.0 stable, let's keep this open until then.

For now, you can safely continue to use 2.5.

And by the way, if what you're trying to achieve with this augmentation is extracting payload type from action creator type, you can use conditional types for that.

@quantuminformation
Copy link

Cool thanks @aikoven

We are seeing this:
Screenshot 2019-03-12 at 07 57 24

@quantuminformation
Copy link

quantuminformation commented Mar 12, 2019

This happened after moving to the new native create react app --typescript.

@aikoven
Copy link
Owner

aikoven commented Mar 12, 2019

@quantuminformation Can you show the definition of SaveIssue action creator?

@quantuminformation
Copy link

export const SaveIssue = actionCreator.async<null, IssueDetails , string>('SaveIssue');

@quantuminformation
Copy link

quantuminformation commented Mar 12, 2019

If I turn off "strict": true,
no error.

before we just had

    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noErrorTruncation": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,```

@quantuminformation
Copy link

Fixed it updating the generic type

export const LoadIssue = actionCreator.async< null, IssueDetails , string>('LoadIssue');
to
export const LoadIssue = actionCreator.async< {issueId: number}, IssueDetails , string>('LoadIssue');

@quantuminformation
Copy link

Have you thought of setting up a discord server for this project, or adding it to reactiflux?

@aikoven
Copy link
Owner

aikoven commented Mar 19, 2019

Have you thought of setting up a discord server for this project, or adding it to reactiflux?

There's not so much activity on this project. And honestly, I don't have much spare time to maintain a chat room.

@quantuminformation
Copy link

ok, thx anyway

aikoven pushed a commit that referenced this issue Sep 14, 2019
@aikoven
Copy link
Owner

aikoven commented Sep 14, 2019

@MistyKuu fixed in v3.0.0.

@aikoven aikoven closed this as completed Sep 14, 2019
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

No branches or pull requests

3 participants