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

Make meta optional (default to undefined) #94

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface FluxStandardAction<Payload, Meta> {
export interface FluxStandardAction<Payload, Meta = undefined> {
/**
* The `type` of an action identifies to the consumer the nature of the action that has occurred.
* Two actions with the same `type` MUST be strictly equivalent (using `===`)
Expand Down Expand Up @@ -26,26 +26,26 @@ export interface FluxStandardAction<Payload, Meta> {
meta: Meta;

Choose a reason for hiding this comment

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

Isn't this supposed to be optional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope. That's the whole point. It should not be optional. See #53 and related discussion.

Copy link

Choose a reason for hiding this comment

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

Hey, sorry to butt in here. Just hit this issue and am a bit confused... Currently I have this issue:

const x: FSA<string, undefined> = { type: "foo", payload: "hello" }
Type '{ type: string; payload: string; }' is not assignable to type 'FluxStandardAction<string, undefined>'.
  Property 'meta' is missing in type '{ type: string; payload: string; }'.

So setting the type to undefined does not make the attribute optional.

I think the DefinitelyTyped defs handle this in a more appropriate way.

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed that here: #53 (comment)

It is debatable on which is a better solution.
I would say when microsoft/TypeScript#12400 (comment) is resolved, we will be just fine.

Copy link

Choose a reason for hiding this comment

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

Ah yeah, makes sense. It's just annoying having to add extra code to satisfy types, but a small price to pay I suppose. :)

}

export interface ErrorFluxStandardAction<CustomError extends Error, Meta> extends FluxStandardAction<CustomError, Meta> {
export interface ErrorFluxStandardAction<CustomError extends Error, Meta = undefined> extends FluxStandardAction<CustomError, Meta> {
error: true;
}

/**
* Alias for FluxStandardAction.
*/
export type FSA<Payload, Meta> = FluxStandardAction<Payload, Meta>;
export type FSA<Payload, Meta = undefined> = FluxStandardAction<Payload, Meta>;

/**
* Alias for ErrorFluxStandardAction.
*/
export type ErrorFSA<CustomError extends Error, Meta> = ErrorFluxStandardAction<CustomError, Meta>;
export type ErrorFSA<CustomError extends Error, Meta = undefined> = ErrorFluxStandardAction<CustomError, Meta>;

/**
* Returns `true` if `action` is FSA compliant.
*/
export function isFSA<Payload, Meta>(action: any): action is FluxStandardAction<Payload, Meta>;
export function isFSA<Payload, Meta = undefined>(action: any): action is FluxStandardAction<Payload, Meta>;

/**
* Returns `true` if `action` is FSA compliant error.
*/
export function isError<CustomError extends Error, Meta>(action: any): action is ErrorFluxStandardAction<CustomError, Meta>;
export function isError<CustomError extends Error, Meta = undefined>(action: any): action is ErrorFluxStandardAction<CustomError, Meta>;