Skip to content

Cloudflare types for env no longer workΒ #18294

@Jiralite

Description

@Jiralite

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

10.26.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

Repository: https://github.com/Jiralite/sentry-cloudflare-env-reproduction

There is a very suspicious pull request, #18064, that seems responsible for this as reverting that definition in 10.26.0 correctly infers env (this means versions 10.23.0 onwards breaks the types).

Steps to Reproduce

  1. Run TypeScript

Expected Result

env is inferred.

Actual Result

source/index.ts:7:44 - error TS18046: 'env' is of type 'unknown'.

7 export default withSentry((env) => ({ dsn: env.SENTRY_DATA_SOURCE_NAME, sendDefaultPii: true }), {
                                             ~~~

source/index.ts:8:2 - error TS2322: Type '(_: Request<unknown, IncomingRequestCfProperties<unknown>>, env: Env) => Response' is not assignable to type 'ExportedHandlerFetchHandler<unknown, unknown>'.
  Types of parameters 'env' and 'env' are incompatible.
    Type 'unknown' is not assignable to type 'Env'.

8  fetch(_, env) {
   ~~~~~

  node_modules/.pnpm/@[email protected]/node_modules/@cloudflare/workers-types/2023-07-01/index.d.ts:520:3
    520   fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
          ~~~~~
    The expected type comes from property 'fetch' which is declared here on type 'ExportedHandler<unknown, unknown, unknown>'


Found 2 errors in the same file, starting at: source/index.ts:7

Additional Context

No response

Priority

React with πŸ‘ to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions