Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Swaps
Runnable<T>
forRunnable<Data, Return>
to preserve inferred types when using theRunnable
interface (or it's derivativeCloudFunction
).This helps with writing tests that call functions, because their return type will be preserved.
However, the main motivation for this change is to help with writing type-safe client/server interactions. The runnable interface gives the client a chance to infer the function's signature.
Functions
functions/index.ts
Client
client/index.ts
client/https-callables.ts
It would be nice if there was a slightly less hacky way to do this, ideally one where you didn't need to bring in your own helper for creating the callable functions, but that's out of scope for this repo/PR.
I'm currently hacking my way around this by overloading the
https.onCall
function with a type declaration, but it would be much nicer if I could get the data/return type directly without it.No Breaking Changes
I added a default value for the
Return
type parameter, which should mean that this isn't a breaking change for anyone currently usingRunnable
.Broken Tests
The changes here surfaced some type errors in some tests, and I went with a quick and dirty fix as it wasn't immediately obvious whether the tests are wrong, or whether they're just taking some type system shortcuts.
The
data
andresource
fields on the event objects inspec/v1/providers/database.spec.ts
don't match up with the definition ofEvent
(fromsrc/cloud-functions.ts
).Specifically, the
data
property should be an instance ofDataSnapshot
. I tried usingconst event: Event = {
but then thecontext.resource
field errors instead, expecting it to be aResource
(src/cloud-functions.ts
) rather than astring
.Let me know if there's a better fix than
any
here and I'll happily amend the PR.Thanks!