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

Route handler return types #1009

Merged
merged 6 commits into from
Dec 2, 2021
Merged

Route handler return types #1009

merged 6 commits into from
Dec 2, 2021

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Nov 30, 2021

This updates the types for RouteHandler to allow for any valid JSON response. Adds number | string | boolean | null as well as arrays of object | number | string | boolean | null.

This is necessary because endpoint can return more than just an object. For instance the project I'm currently working on adding mirage too has an endpoint that returns just a number. Which is totally valid however using the current types without this change causes typescript to emit an error.

@IanVS
Copy link
Collaborator

IanVS commented Nov 30, 2021

This makes sense to me. Would you mind adding some type tests that fail without this change and pass with it? Thanks!

@pleek91
Copy link
Contributor Author

pleek91 commented Nov 30, 2021

@IanVS I added some tests though I'm not 100% sure I did them right. Couldn't get them to fail even though vscode showed errors when I didn't have the new types.

Copy link
Collaborator

@IanVS IanVS left a comment

Choose a reason for hiding this comment

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

I think the tests are good. I reverted out your first commit to run the tests without your changes, and they do indeed fail with errors like:

ERROR: 26:20  expect  TypeScript@4.0 compile error:
Argument of type '() => number' is not assignable to parameter of type 'RouteHandler<AnyRegistry>'.
  Type 'number' is not assignable to type 'MaybePromise<object | Response | { id?: string | undefined; attrs: {}; modelName: string; save(): void; update<K extends never>(key: K, value: {}[K]): void; update(changes: Partial<{}>): void; destroy(): void; reload(): void; }>'.

types/index.d.ts Outdated Show resolved Hide resolved
types/tests/server-test.ts Show resolved Hide resolved
Copy link
Collaborator

@IanVS IanVS left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the PR!

@IanVS IanVS merged commit 00e0844 into miragejs:master Dec 2, 2021
@pleek91
Copy link
Contributor Author

pleek91 commented Dec 2, 2021

Thanks for your help/input!

@pleek91
Copy link
Contributor Author

pleek91 commented Dec 2, 2021

How and when would this get released? Just not sure what the process/timeframe is

@IanVS
Copy link
Collaborator

IanVS commented Dec 2, 2021

I'm trying to see if there are any other PRs I can get merged in, and then I'll try cutting a release today.

@IanVS
Copy link
Collaborator

IanVS commented Dec 2, 2021

Turns out I don't have publishing rights to npm, so we need to wait for @samselikoff to do that part.

@samselikoff
Copy link
Contributor

Happy to add you & don’t want to block! What’s your npm username

@IanVS
Copy link
Collaborator

IanVS commented Dec 2, 2021

@samselikoff thanks. I'm ianvs on npm as well.

@samselikoff
Copy link
Contributor

samselikoff commented Dec 3, 2021 via email

@IanVS
Copy link
Collaborator

IanVS commented Dec 3, 2021

Thanks, it looks like I'm added to ember-cli-mirage, but not miragejs. I don't use ember, so you may as well remove me from that one, and if you could add me to https://www.npmjs.com/package/miragejs that would be perfect.

@samselikoff
Copy link
Contributor

samselikoff commented Dec 3, 2021 via email

@IanVS
Copy link
Collaborator

IanVS commented Dec 3, 2021

@pleek91, 0.1.43 has been released with your changes. Thanks again, everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants