question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'cf' does not exist on type 'Request'

See original GitHub issue

I tried adding this library to an existing Creact-React-App application.

I’ve added a hello world function, and I wrote this:

export const onRequest: PagesFunction = async (context) => {
  // Contents of context object
  const {
    request, // same as existing Worker API
    env, // same as existing Worker API
    params, // if filename includes [id] or [[path]]
    waitUntil, // same as ctx.waitUntil in existing Worker API
    next, // used for middleware or to fetch assets
    data, // arbitrary space for passing data between middlewares
  } = context;

  return new Response(
    JSON.stringify({
      country: request.cf.country,
      continent: request.cf.continent,
    })
  );
};

However I am getting error:

Property 'cf' does not exist on type 'Request'.ts(2339)

With //@ts-ignore it works just fine though.

What am I missing here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
CMCDragonkaicommented, Jul 28, 2022

Yea this doesn’t work for me. The "types": ["@cloudflare/workers-types"] doesn’t do anything to my vscode.

I’ve written alot of TS, and most TS projects use the @types convention? Why not use that so we can just install @types/cloudflare-workers-types into dev dependencies.

0reactions
qwtelcommented, Oct 17, 2022

The problem could be related to a (dev) dependency pulling in lib.dom or lib.webworker types via comment. You can find them with

grep -r '<reference lib="dom" />' node_modules/
grep -r '<reference lib="webworker" />' node_modules/
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Error: Property 'user' does not exist on type 'Request'
Be advised that "user" is not a property that is available natively in the Request object of Express. Make sure that you are...
Read more >
property 'extend' does not exist on type 'typeof - You.com
I'm trying to add a menu bar to videoJS control bar in TypeScript but I'm getting an error saying "Property 'extend' does not...
Read more >
Unable to compile TypeScript. Property 'user' does not exist on ...
Hello, I getting annoyed about typescript in my node api. I have written a jwtverify.ts. At first typescript has not accepted the req.user....
Read more >
Request · Cloudflare Workers docs
Cloudflare-specific properties that can be set on the Request that ... The request.cf object is not available in the Cloudflare Workers ...
Read more >
How to extend the Express Request object in TypeScript
Let's learn how to extend the Request type in TypeScript to make its ... Property 'user' does not exist on type 'Request<ParamsDictionary, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found