Skip to content

Commit

Permalink
Improve generic naming
Browse files Browse the repository at this point in the history
  • Loading branch information
unional committed Nov 18, 2016
1 parent 7e51e3a commit 421cac2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface FluxStandardAction<T, M> {
export interface FluxStandardAction<Payload, Meta> {
/**
* 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 All @@ -11,7 +11,7 @@ export interface FluxStandardAction<T, M> {
* By convention, if `error` is `true`, the `payload` SHOULD be an error object.
* This is akin to rejecting a promise with an error object.
*/
payload?: T;
payload?: Payload;
/**
* The optional `error` property MAY be set to true if the action represents an error.
* An action whose `error` is true is analogous to a rejected Promise.
Expand All @@ -23,24 +23,24 @@ export interface FluxStandardAction<T, M> {
* The optional `meta` property MAY be any type of value.
* It is intended for any extra information that is not part of the payload.
*/
meta?: M
meta?: Meta
}

export interface ErrorFluxStandardAction<E extends Error, M> extends FluxStandardAction<E, M> {
export interface ErrorFluxStandardAction<CustomError extends Error, Meta> extends FluxStandardAction<CustomError, Meta> {
error: true
}

/**
* Alias to FluxStandardAction for shorthand
*/
export type FSA<T, M> = FluxStandardAction<T, M>;
export type FSA<Payload, Meta> = FluxStandardAction<Payload, Meta>;

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

/**
* Returns `true` if `action` is FSA compliant error.
*/
export function isError<E extends Error>(action: any): action is ErrorFluxStandardAction<E, any>;
export function isError<CustomError extends Error, Meta>(action: any): action is ErrorFluxStandardAction<CustomError, Meta>;
2 changes: 1 addition & 1 deletion test/typings-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function reducer(state, action) {
let iserr: true = action.error // iserr === true
let err: Error = action.payload
}
else if (isError<MyError>(action)) {
else if (isError<MyError, void>(action)) {
let err: MyError = action.payload
}
}
Expand Down

0 comments on commit 421cac2

Please sign in to comment.