Comments (8)
I think it might be caused by the Svelte VSCode extension, so filed an issue there for now: sveltejs/language-tools#1733
Thanks for the help on figuring it out !! ❤️
from workers-types.
This is hit&miss, but in some cases, it worked for me when to add /// <reference types="@cloudflare/workers-types" />
as the very first line in the TypeScipt file, to help it reference CF types vs lib.dom
.
from workers-types.
It seems like you might be trying to use workers-types
in combination with libdom
? That's generally not a path we recommend (see the README on npm for the recommended setup). However, with the just-released workers-types@4
, you're able to import the types, which may help:
import type { Request as WorkersRequest } from "@cloudflare/workers-types"
from workers-types.
It's probably fine to close this, but the problem is caused by two nuances so I'll leave further notes here -
- IDEs often include TypeScript's
lib.dom.d.ts
for all.ts
files even iftsconfig.json
has a narrow list of libs like"lib": ["ES2020"]
- When the code references global objects like
new Request(url)
, the IDE will use the definition ofRequest
fromlib.dom.d.ts
that ships with TypeScript, which has incorrect types (for example, thecf
parameter is missing). Importing the custom type for Request from@cloudflare/workers-types
will not help because the code uses the actualnew Request()
runtime object which cannot be (reasonably) changed in type via TS type hints.
That's why the workaround is to tell TypeScript to use @cloudflare/workers-types
for that file as I showed in the example above. In theory, doing this override in tsconfig.json with the types
directive works the same (as is explained in the README), but that didn't do the trick for me several times.
from workers-types.
@penalosa I don't have libdom
anywhere. My tsconfig.json
is the same as what's suggested in the README, except I have "module": "esnext"
instead of "CommonJS"
.
@eugene1g Adding /// <reference types="@cloudflare/workers-types" />
to the start of the file doesn't seem to fix it unfortunately. Also, the cf
parameter isn't missing for me - I have both cf
and mode
, etc.
from workers-types.
@probablykasper If you're seeing cf
and mode
, that's definitely unexpected behaviour. It's most likely that libdom or libwebworker is being included somewhere (perhaps by a framework you're using?), but could you clarify the version of the types you're using, and whether @cloudflare/workers-types@4
fixes the issue?
from workers-types.
I'm using v4 now, but it was also an issue on v3
from workers-types.
Would you be able to set up a reproduction repository?
from workers-types.
Related Issues (20)
- Missing properties on IncomingRequestCfPropertiesBotManagement HOT 1
- Incorrect D1 types HOT 2
- RequestInit is missing some properties like 'cache' HOT 3
- Generate types from `workerd` RTTI HOT 1
- RFC: Exportable types HOT 7
- Fix `request.cf` types
- Generate exportable version of `workers-types` HOT 1
- add JSDocs documentation in types
- Move overrides to `workerd` C++ source code HOT 1
- Include C++ parameter names in types generated from JSG RTTI HOT 2
- Get type hints on incoming Request object HOT 4
- IncomingRequestCfPropertiesGeographicInformation makes geo property access an error (regression from 3.17.0) HOT 7
- HtmlRewriter ElementHandler methods can only accept strings (not general Content) HOT 1
- (3.18.0) IncomingRequestCfPropertiesGeographicInformation is the wrong type HOT 2
- Class 'Request<ParamKeyType, Data>' incorrectly extends base class 'Body' HOT 1
- addEventListener has a broken type definition HOT 1
- NPM Release @cloudflare/worker-types 4.20221111.0 HOT 2
- Add Symbol.iterator to WebScoketPair HOT 1
- What is Fetcher for? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workers-types.