diff --git a/src/index.d.ts b/src/index.d.ts index 2a1b2d0..375ac65 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -11,7 +11,7 @@ export interface FluxStandardAction { * 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?: Payload; + 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. @@ -23,7 +23,7 @@ export interface FluxStandardAction { * 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?: Meta + meta: Meta } export interface ErrorFluxStandardAction extends FluxStandardAction { diff --git a/test/typings-test.ts b/test/typings-test.ts index efdd53f..634bfee 100644 --- a/test/typings-test.ts +++ b/test/typings-test.ts @@ -12,7 +12,7 @@ interface MyError extends Error { someField: string; } -function createCustomAction(payload: CustomPayload): FluxStandardAction { +function createCustomAction(payload: CustomPayload) { return { type: 'custom', payload @@ -31,6 +31,16 @@ function isCustomAction3(action: any): action is FluxStandardAction { + return true +} + +let action2 = {} +if (isCustomAction4(action2)) { + // type guard infers payload will not be undefined + console.log(action2.payload.message) +} + function reducer(state, action) { if (isFSA(action)) { let a: number = action.payload.a; diff --git a/tsconfig.json b/tsconfig.json index b608449..3989eef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,8 @@ { "compilerOptions": { - "outDir": "tsc-out" + "outDir": "tsc-out", + "strictNullChecks": true, + "target": "es5" }, "files": [ "test/typings-test.ts"