-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite middleware support: Request type missing export and .originalUrl
method & url
setting
#249
Comments
Interesting, this seems to be some sort of undocumented legacy usage of a property from Express.js Both the Do you want to make a PR which resolves this or should I push a minor version update? I believe I implemented originalUrl as just a setter which would explain your error, so a simple setter should do the trick. |
Yep, I saw them, but I don't really know what happened with the exports. The VS code linter doesn't complain (even links to the .d.ts type), yet tsc creates a "class MyRequest extends undefined", which leads to an error at runtime.
I can do it, but I have no idea how to fix the import/export issue.
Ok, I'm making a PR with those setters asap. |
Actually, I just realized there are discrepancies between the type definitions/exports and the js source files. ExportsThe exported type definitions: hyper-express/types/index.d.ts Lines 1 to 11 in f5111f8
The JavaScript exports: Lines 16 to 20 in f5111f8
So typescript thinks that the types are available, but the underlying source code is missing (since the actual javascript doesn't export any Request or anything). PropertiesTypes definitions: hyper-express/types/components/http/Request.d.ts Lines 204 to 218 in f5111f8
Exported JavaScript class: Missing ExpressRequest and ExpressResponse type declarationsSelf explainatory, see: /src/components/compatibility The main issue for the discrepancies is not having a single source of truth (ie, typescript .ts files) - to be fair: you need to be a madman to port everything in full typescript .ts source code, so I'm not asking for this "better solution" How would you like me to fix the Request class @kartikk221 ? |
Wait, I am confused. Shouldn't TypeScript be using the index.d.ts as the truth for its resolving? The JSDoc types and Typescript types are "loosely" similar because certain precision can be achieved in TypeScript which can't be achieved in JSDoc hence the differences. |
I was also confused (I never worked with .d.ts), in theory I think .d.ts files can also avoid using the same folder structure as the javascript source code, thus the compiler won't actually look for the exports as if it was a mirror. Easy peasy solution with the exports in
Same goes for any other javascript classes that were exported in the .d.ts |
Exporting Also, I saw there's an ExpressRequest/Response javscript class, but no type definition, is it still experimental or is it ready --> should I work on the .d.ts types? |
If exporting on the JS side solves the issue then I guess I don't see the issue. I just don't understand why the JS has to line up with .d.ts types since it defeats the purpose of the .d.ts types. The types for ExpressRequest are not documented and need to be documented / extended through the .d.ts types. |
Greetings, I wanted to use vite together with hyper-express and tsx for a full API+backend developing (production ready) server.
Unluckily, the vite server (mis?)uses the req object and writes to the url property + it also uses the
originalUrl
property.Request
and extending it. Typescript is not complaining while building, however the library doesn't export the type, not sure why.Cannot set property originalUrl of #<Request> which has only a getter
url
property, not sure if it's bad practice (I think so, but anyway).Workarounds:
set url(value) { this._url = value; }
in the source Request.js classSolutions:
The text was updated successfully, but these errors were encountered: