aikoven / typescript-fsa

Type-safe action creator utilities
MIT License
607 stars 28 forks source link

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

Closed MistyKuu closed 5 years ago

MistyKuu commented 5 years ago

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 commented 5 years ago

is this lib still maintained?

aikoven commented 5 years ago

@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 https://github.com/Microsoft/TypeScript/pull/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 commented 5 years ago

Cool thanks @aikoven

We are seeing this:

Screenshot 2019-03-12 at 07 57 24
quantuminformation commented 5 years ago

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

aikoven commented 5 years ago

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

quantuminformation commented 5 years ago

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

quantuminformation commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

aikoven commented 5 years ago

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 commented 5 years ago

ok, thx anyway

aikoven commented 5 years ago

@MistyKuu fixed in v3.0.0.