forked from the-dr-lazy/deox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: type for plain action creator. (the-dr-lazy#144)
* fix: type for plain action creator. Fixes the-dr-lazy#143 * fix: more type tests for createActionCreator * fix: adjustments after code review Co-authored-by: Mohammad Hasani <[email protected]>
- Loading branch information
1 parent
9925130
commit f228b81
Showing
4 changed files
with
277 additions
and
17 deletions.
There are no files selected for viewing
122 changes: 115 additions & 7 deletions
122
src/__tests__/__snapshots__/create-action-creator.dts.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,143 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createActionCreator const todoAdd = createActionCreator( | ||
'[Todo] add', | ||
// tslint:disable-next-line:no-inferrable-types | ||
resolve => (name: string, completed: boolean = false) => | ||
resolve({ name, completed }) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
|
||
exports[`createActionCreator const todoAdd2 = createActionCreator( | ||
'[Todo] add', | ||
// tslint:disable-next-line:no-inferrable-types | ||
resolve => (name: string, completed: boolean = false) => | ||
resolve({ name, completed }, 'Meta data of all todos') | ||
) (type) should match snapshot 1`] = `"any"`; | ||
|
||
exports[`createActionCreator const todoFetchRejected = createActionCreator('[Todo] fetch rejected', resolve => (error: Error) => | ||
resolve(error) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
|
||
exports[`createActionCreator const todoFetchRejected2 = createActionCreator( | ||
'[Todo] fetch rejected', | ||
resolve => (error: Error, meta?: { status: number }) => resolve(error, meta) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
|
||
exports[`createActionCreator const todoGeneric = createActionCreator('[Todo] generic', resolve => <Name>(name: Name) => | ||
resolve(name) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
exports[`createActionCreator const todoGeneric2 = createActionCreator( | ||
'[Todo] generic', | ||
resolve => <Name, Meta>(name: Name, meta: Meta) => resolve(name, meta) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
exports[`createActionCreator const todoTruncate = createActionCreator('[Todo] truncate') (type) should match snapshot 1`] = `"any"`; | ||
exports[`createActionCreator const todoVarArgs = createActionCreator( | ||
'[Todo] var-args', | ||
resolve => (...names: string[]) => resolve(names) | ||
) (type) should match snapshot 1`] = `"any"`; | ||
exports[`createActionCreator createActionCreator( | ||
'[Todo] add', | ||
// tslint:disable-next-line:no-inferrable-types | ||
resolve => (name: string, completed: boolean = false) => | ||
resolve({ name, completed }) | ||
) (type) should match snapshot 1`] = `"((name: string, completed?: boolean) => { type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; }) & { type: \\"[Todo] add\\"; toString(): \\"[Todo] add\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] add\\", (name: string, completed?: boolean) => { type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; }>"`; | ||
exports[`createActionCreator createActionCreator( | ||
'[Todo] add', | ||
// tslint:disable-next-line:no-inferrable-types | ||
resolve => (name: string, completed: boolean = false) => | ||
resolve({ name, completed }, 'Meta data of all todos') | ||
) (type) should match snapshot 1`] = `"((name: string, completed?: boolean) => { type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; meta: string; }) & { type: \\"[Todo] add\\"; toString(): \\"[Todo] add\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] add\\", (name: string, completed?: boolean) => { type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; meta: string; }>"`; | ||
exports[`createActionCreator createActionCreator( | ||
'[Todo] fetch rejected', | ||
resolve => (error: Error, meta?: { status: number }) => resolve(error, meta) | ||
) (type) should match snapshot 1`] = `"((error: Error, meta?: { status: number; } | undefined) => { type: \\"[Todo] fetch rejected\\"; payload: Error; meta: { status: number; }; error: true; }) & { type: \\"[Todo] fetch rejected\\"; toString(): \\"[Todo] fetch rejected\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] fetch rejected\\", (error: Error, meta?: { status: number; } | undefined) => { type: \\"[Todo] fetch rejected\\"; payload: Error; meta: { status: number; }; error: true; }>"`; | ||
exports[`createActionCreator createActionCreator( | ||
'[Todo] generic', | ||
resolve => <Name, Meta>(name: Name, meta: Meta) => resolve(name, meta) | ||
) (type) should match snapshot 1`] = `"(<Name, Meta>(name: Name, meta: Meta) => Action<\\"[Todo] generic\\", Name, Meta>) & { type: \\"[Todo] generic\\"; toString(): \\"[Todo] generic\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] generic\\", <Name, Meta>(name: Name, meta: Meta) => Action<\\"[Todo] generic\\", Name, Meta>>"`; | ||
exports[`createActionCreator createActionCreator( | ||
'[Todo] var-args', | ||
resolve => (...names: string[]) => resolve(names) | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] var-args\\", (...names: string[]) => { type: \\"[Todo] var-args\\"; payload: string[]; }>"`; | ||
exports[`createActionCreator createActionCreator('[Todo] fetch rejected', resolve => (error: Error) => | ||
resolve(error) | ||
) (type) should match snapshot 1`] = `"((error: Error) => { type: \\"[Todo] fetch rejected\\"; payload: Error; error: true; }) & { type: \\"[Todo] fetch rejected\\"; toString(): \\"[Todo] fetch rejected\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] fetch rejected\\", (error: Error) => { type: \\"[Todo] fetch rejected\\"; payload: Error; error: true; }>"`; | ||
exports[`createActionCreator createActionCreator('[Todo] generic', resolve => <Name>(name: Name) => | ||
resolve(name) | ||
) (type) should match snapshot 1`] = `"(<Name>(name: Name) => Action<\\"[Todo] generic\\", Name, undefined>) & { type: \\"[Todo] generic\\"; toString(): \\"[Todo] generic\\"; }"`; | ||
) (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] generic\\", <Name>(name: Name) => Action<\\"[Todo] generic\\", Name, undefined>>"`; | ||
exports[`createActionCreator createActionCreator('[Todo] truncate') (type) should match snapshot 1`] = `"ExactActionCreator<\\"[Todo] truncate\\", () => { type: \\"[Todo] truncate\\"; }>"`; | ||
exports[`createActionCreator todoAdd('buy presents') (type) should match snapshot 1`] = `"{ type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; }"`; | ||
exports[`createActionCreator todoAdd('buy presents', true) (type) should match snapshot 1`] = `"{ type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; }"`; | ||
exports[`createActionCreator todoAdd('buy presents', true, 42) (type) should match snapshot 1`] = `"Expected 1-2 arguments, but got 3."`; | ||
exports[`createActionCreator todoAdd() (type) should match snapshot 1`] = `"Expected 1-2 arguments, but got 0."`; | ||
exports[`createActionCreator todoAdd(false) (type) should match snapshot 1`] = `"Argument of type 'false' is not assignable to parameter of type 'string'."`; | ||
exports[`createActionCreator todoAdd2('buy presents') (type) should match snapshot 1`] = `"{ type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; meta: string; }"`; | ||
exports[`createActionCreator todoAdd2('buy presents', true) (type) should match snapshot 1`] = `"{ type: \\"[Todo] add\\"; payload: { name: string; completed: boolean; }; meta: string; }"`; | ||
exports[`createActionCreator todoAdd2() (type) should match snapshot 1`] = `"Expected 1-2 arguments, but got 0."`; | ||
exports[`createActionCreator todoFetchRejected() (type) should match snapshot 1`] = `"Expected 1 arguments, but got 0."`; | ||
exports[`createActionCreator todoFetchRejected(new Error('')) (type) should match snapshot 1`] = `"{ type: \\"[Todo] fetch rejected\\"; payload: Error; error: true; }"`; | ||
exports[`createActionCreator todoFetchRejected2() (type) should match snapshot 1`] = `"Expected 1-2 arguments, but got 0."`; | ||
exports[`createActionCreator todoFetchRejected2(new Error('')) (type) should match snapshot 1`] = `"{ type: \\"[Todo] fetch rejected\\"; payload: Error; meta: { status: number; }; error: true; }"`; | ||
exports[`createActionCreator todoFetchRejected2(new Error(''), { status: '' }) (type) should match snapshot 1`] = ` | ||
"Argument of type '{ status: string; }' is not assignable to parameter of type '{ status: number; }'. | ||
Types of property 'status' are incompatible. | ||
Type 'string' is not assignable to type 'number'." | ||
`; | ||
exports[`createActionCreator todoFetchRejected2(new Error(''), { status: 200 }) (type) should match snapshot 1`] = `"{ type: \\"[Todo] fetch rejected\\"; payload: Error; meta: { status: number; }; error: true; }"`; | ||
exports[`createActionCreator todoGeneric('buy presents') (type) should match snapshot 1`] = `"{ type: \\"[Todo] generic\\"; payload: string; }"`; | ||
exports[`createActionCreator todoGeneric('buy presents', true) (type) should match snapshot 1`] = `"Expected 1 arguments, but got 2."`; | ||
exports[`createActionCreator todoGeneric() (type) should match snapshot 1`] = `"Expected 1 arguments, but got 0."`; | ||
exports[`createActionCreator todoGeneric(false) (type) should match snapshot 1`] = `"{ type: \\"[Todo] generic\\"; payload: false; } | { type: \\"[Todo] generic\\"; payload: true; }"`; | ||
exports[`createActionCreator todoGeneric2('The answer', 42) (type) should match snapshot 1`] = `"{ type: \\"[Todo] generic\\"; payload: string; meta: number; }"`; | ||
exports[`createActionCreator todoGeneric2('The answer', 42, 'Zaphod') (type) should match snapshot 1`] = `"Expected 2 arguments, but got 3."`; | ||
exports[`createActionCreator todoGeneric2() (type) should match snapshot 1`] = `"Expected 2 arguments, but got 0."`; | ||
exports[`createActionCreator todoGeneric2(42) (type) should match snapshot 1`] = `"Expected 2 arguments, but got 1."`; | ||
exports[`createActionCreator todoGeneric2(42, 'The answer') (type) should match snapshot 1`] = `"{ type: \\"[Todo] generic\\"; payload: number; meta: string; }"`; | ||
exports[`createActionCreator todoTruncate('') (type) should match snapshot 1`] = `"Expected 0 arguments, but got 1."`; | ||
exports[`createActionCreator todoTruncate() (type) should match snapshot 1`] = `"{ type: \\"[Todo] truncate\\"; }"`; | ||
exports[`createActionCreator todoVarArgs('Attend Christmas Party', 'Wish everyone a Merry Christmas') (type) should match snapshot 1`] = `"{ type: \\"[Todo] var-args\\"; payload: string[]; }"`; | ||
exports[`createActionCreator todoVarArgs('Dress Up like Santa', 'Ignore numbers 1-3', 'Steal Christmas!') (type) should match snapshot 1`] = `"{ type: \\"[Todo] var-args\\"; payload: string[]; }"`; | ||
exports[`createActionCreator todoVarArgs('Make Cookies') (type) should match snapshot 1`] = `"{ type: \\"[Todo] var-args\\"; payload: string[]; }"`; | ||
exports[`createActionCreator todoVarArgs() (type) should match snapshot 1`] = `"{ type: \\"[Todo] var-args\\"; payload: string[]; }"`; | ||
exports[`createActionCreator createActionCreator('[Todo] truncate') (type) should match snapshot 1`] = `"(<_T>(...args: any[]) => { type: \\"[Todo] truncate\\"; }) & { type: \\"[Todo] truncate\\"; toString(): \\"[Todo] truncate\\"; }"`; | ||
exports[`createActionCreator todoVarArgs(false) (type) should match snapshot 1`] = `"Argument of type 'false' is not assignable to parameter of type 'string'."`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters