Closed jketcham closed 2 years ago
Locally I was able to remove the const
declaration from this enum in cloudevents:
and was able to get the type working correctly.
Added some more findings on the issue in this comment.
Hey @jketcham, can you provide an exact reproduction of the issue with some code?
Have you tried importing CloudEvent
instead? We decided to use the official CESDK for JS types. If there's a problem using them, we should fix that.
In terms of guidance, we provide a set of types in this file:
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/src/functions.ts
Which should be exported by default with the FF, from here:
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/src/index.ts
A minimal sample of the issue would help.
Hi @grant, I think the issue I ran into should be resolved when the next version of cloudevents/sdk-javascript
is released and can be used in this library.
For reference, the code I had previously that was working fine was importing CloudEventsContext
like:
import { CloudEventsContext } from '@google-cloud/functions-framework';
I updated my code to instead import the Context
type and the only problem there was the Cannot access ambient const enums
error coming from the cloudevents library (which should be resolved in the next release).
OK, we will wait for a new version of cloudevents
. https://github.com/cloudevents/sdk-javascript/issues/456
Hey @grant, I just tested out the new release for 3.0.0 with the update including cloudevents@5.3.2
and unfortunately am still getting the same error it seems 🤔
I created a repo that reproduces the issue here: https://github.com/jketcham/cloudevents-ambient-const-enums
This code is still giving that ambient const enums error when running tsc --noEmit
with the latest versions:
import type { CloudEventV1 } from 'cloudevents';
import type { Context } from '@google-cloud/functions-framework';
export function handleWithCloudEvent(context: CloudEventV1<unknown>) {
console.log({ context });
}
export function handleWithContext(context: Context) {
console.log({ context });
}
I have a cloud function (triggered by PubSub) I've written in Typescript and transpiled with babel which was using the
CloudEventsContext
type exported in version1.9.0
. When I tried to upgrade to version2.1.1
, I now get the following errors:It looks like I should now be using the
Context
type, but them I'm running into the sameCannot access ambient const enums
error with the--isolatedModules
flag, which looks like it's related to this issue with cloudevents itself: https://github.com/cloudevents/sdk-javascript/issues/456.Can anyone provide any guidance on how I should type my cloud functions with CloudEvent context going forward? Is this something that needs to be addressed in the cloudevents repo?
Thank you!