-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for full stack type safety
- Loading branch information
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
getTask, | ||
getTasks, | ||
createTask, | ||
updateTaskIsDone, | ||
deleteCompletedTasks, | ||
toggleAllTasks, | ||
getNumTasks, | ||
getDate, | ||
getAnything, | ||
getTrueVoid, | ||
} from 'wasp/client/operations' | ||
import { Task } from 'wasp/entities' | ||
import { Payload } from 'wasp/server/_types' | ||
|
||
// For the details of this specification, see | ||
// https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471 | ||
|
||
// This should be [], | ||
// but I couldn't get it to work yet. | ||
type VoidOperationPayload = [args?: void | undefined] | ||
|
||
// When the user doesn't specify an operation payload, | ||
// we want to be as permissive as possible. | ||
type UnspecifiedOperationPayload = [args?: unknown] | ||
|
||
type TQ1 = Assert< | ||
InputsAndOutputsAre<typeof getTask, [Pick<Task, 'id'>], Promise<Task>> | ||
> | ||
|
||
type TQ2 = Assert< | ||
InputsAndOutputsAre<typeof getTasks, VoidOperationPayload, Promise<Task[]>> | ||
> | ||
|
||
type TQ3 = Assert< | ||
InputsAndOutputsAre<typeof getNumTasks, VoidOperationPayload, Promise<number>> | ||
> | ||
|
||
type TQ4 = Assert< | ||
InputsAndOutputsAre<typeof getDate, VoidOperationPayload, Promise<Date>> | ||
> | ||
|
||
type TQ5 = Assert< | ||
InputsAndOutputsAre< | ||
typeof getAnything, | ||
UnspecifiedOperationPayload, | ||
Promise<Payload> | ||
> | ||
> | ||
|
||
type TQ6 = Assert< | ||
InputsAndOutputsAre<typeof getTrueVoid, VoidOperationPayload, Promise<string>> | ||
> | ||
|
||
type TA1 = Assert< | ||
InputsAndOutputsAre< | ||
typeof createTask, | ||
[Pick<Task, 'description'>], | ||
Promise<Task> | ||
> | ||
> | ||
|
||
type TA2 = Assert< | ||
InputsAndOutputsAre< | ||
typeof updateTaskIsDone, | ||
[Pick<Task, 'id' | 'isDone'>], | ||
Promise<Payload> | ||
> | ||
> | ||
|
||
type TA3 = Assert< | ||
InputsAndOutputsAre< | ||
typeof deleteCompletedTasks, | ||
UnspecifiedOperationPayload, | ||
Promise<Payload> | ||
> | ||
> | ||
|
||
type TA4 = Assert< | ||
InputsAndOutputsAre< | ||
typeof toggleAllTasks, | ||
UnspecifiedOperationPayload, | ||
Promise<Payload> | ||
> | ||
> | ||
|
||
type InputsAndOutputsAre< | ||
OperationType extends (...args: any[]) => any, | ||
ExpectedParams, | ||
ExpectedReturn | ||
> = { | ||
params: AreEqual<Parameters<OperationType>, ExpectedParams> | ||
return: AreEqual<ReturnType<OperationType>, ExpectedReturn> | ||
} | ||
|
||
type Assert<T extends { params: true; return: true }> = T | ||
|
||
type AreEqual<T, Expected> = T extends Expected | ||
? Expected extends T | ||
? true | ||
: false | ||
: false |