firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Make WrappedFunction curry type info #138

Closed inlined closed 2 years ago

inlined commented 2 years ago

Sorry that the formatter made a bunch of changes. The majority of the impactful changes here are that the wrapped function types keep the type info of the functions that they wrap. This also required us a fix to the CloudFunction type because it is now generic based on an EventType rather than event data so that we can keep type info for subtypes of CloudEvent.

I'd like to eventually look at refactoring this to have fewer places where we have any. I think we might want to have three pieces:

function baseEvent<T>(): Omit<CloudEvent<any>, 'data'> that returns what you have today. Then in each partial you do the combination of baseEvent with per-event type overrides (e.g. bucket for Storage) and the partial data. By putting the event construction lower in the stack we can make sure data is referentially correct (e.g. the StorageEvent.bucket matches the StorageEvent.data.bucket)