-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
feat: Moving types into the repo #6382
base: master
Are you sure you want to change the base?
Conversation
Updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
I hope to attend the TSC meeting tomorrow, so we could probably discuss this approach. |
@RobinTail, the meeting is in 4 hours. |
This one is merged DefinitelyTyped/DefinitelyTyped#72159 . |
DT also has tests for the types and I'm thinking about having ones here as well. |
… typescript config).
Are these types identical to @types/express on NPM from DefinitelyTyped? There are no issues at runtime or in plain JavaScript, it all runs as expected, it's only the types causing the inspection error. In plain JavaScript and type stripped TypeScript the usage is valid and throws no errors. It is only the type definitions that make TypeScript believe it is invalid. import { Router } from "express";
// TS2350: Only a void function can be called with the new keyword.
const router = new Router();
// This does not cause any errors.
const router = Router(); For router.use it does not seem to detect the parameter types when the function returns anything but void. // Does not error, perfectly fine.
router.use((request: Request, response: Response) => {});
// Does not error, perfectly fine.
router.use("/test", (request: Request, response: Response) => {
return void response.json({});
});
// TS2769: No overload matches this call.
router.use("/test", (request: Request, response: Response) => {
return response.json({});
});
// TS2769: No overload matches this call.
router.use((request: Request, response: Response) => response.json({})); The same error also occurs with get, post, and put for the same reasons. // Does not error, perfectly fine.
router.get("/test", (request: Request, response: Response) => {
return void response.json({});
});
// TS2769: No overload matches this call.
router.get("/test", (request: Request, response: Response) => response.json({}));
router.post("/test", (request: Request, response: Response) => response.json({}));
router.put("/test", (request: Request, response: Response) => response.json({})); Currently anyone running TypeScript without @types/express does not have these errors. Or perhaps I should create an issue and point these out once types are officially in express? |
Yes,
The requirement of returning
It's not "valid" — it's not being validated at all, which comes from your previous statement that someone is running Typescript without having actual types installed. When Valid is to return Therefore, it helps either to add the router.get("/test", (request, response) => void response.json({}));
router.get("/test", (request, response) => { response.json({}); }); In case you have an idea on improving v5 types, you can make a PR to DT, @xPuls3 , and when it's merged, I will update my PR with your improvements. |
It's valid in that its properly handled by the library in the way its used in JavaScript and during actual runtime. Types being known is not a requirement for validity in a library that does not have any types. Issues with the the unofficial types not even in the repository does not define what is valid inside the official library. I notice you didn't mention the inspection error that occurs when using new on the router class, which again, is valid and is handled correctly, the types arbitrarily claim it is incorrect despite the imported function working as a constructor and being referred to as a class inside the documentation, this feels like an oversight. I'd rather have the types default to "any" than have incorrect types as that defeats the purpose. I don't think incomplete types that cause errors in "valid" (see above) code should be made official unless the current issues with it are first resolved. That's just how I see it though, others may think differently. |
It won't be merged until Express 6, @xPuls3. So I think you're safe for about a decade. |
Address expressjs/discussions#192 , labeled as "top priority".
express.query
— it was removed in 5.0.0-alpha.1express.query
type forexpress
v5 DefinitelyTyped/DefinitelyTyped#72159typescript-eslint
(ESLint updated and configured)tsc
and expect-type assertions based on DT tests