-
-
Notifications
You must be signed in to change notification settings - Fork 3.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
Distribute TypeScript types with koa package #1607
Comments
sometimes i don't get it, vscode is able to follow js and understand jsdoc without having separate type definition files. I most often see this @types as unnecessary |
I'll leave this open for now but there's little engagement from maintainers to add/update TS support in any form to this repo. |
Sure, maybe. I get it. I just have no personal stake in getting TS in so I will not push for it. If anything adding TS typings might just push me to leave entirely (not that anyone would care :), I'm just saying, it's not an investment I care to take on at least). Edit: Ooops, sorry, closed by mistake. Also, I just want to clarify by "leaving". I ment as a member of the maintainer group. I'm not active enough to take decisions like these anyway, so I just peak when I find the time. I could do some minor stuff when necessary but if I also had to consider TS (which I'm personally not a fan of) I would just accept that Koa isn't for me to care about anymore :). Maybe the next generation of Koa users would consider it, but again, I'm not even comfortable inviting new members at this point due to my inactivity here! |
The best way to add type safety to Koa would be to use TypeScript JSDoc comments. Add a
Because
If Node.js types are only used in non-published modules (i.e. tests) then it could be a dev dependency instead with the latest version:
Any other In edge cases you could add types as optional peer dependencies if your package ships modules for multiple different frameworks where a user is expected to only use one in their project, for example Add a {
"compilerOptions": {
"maxNodeModuleJsDepth": 10,
"module": "nodenext",
"noEmit": true,
"strict": true
},
"typeAcquisition": {
"enable": false
}
} Then add a type check package script like this:
That doesn't emit anything, it just checks the types of the project modules for CI. Add this at the top of any modules you want type checked (usually all of them): // @ts-check Then you can use TypeScript JSDoc comments for type safety, like this: I truly believe this is as simple as it gets for having type safety as the types are inherently part of the modules that are shipped, and there is no build step. This is particularly great when publishing universal modules that work in both Node.js and Deno projects with TypeScript, as Deno with HTTP imports doesn't have a concept of Koa already is using relatively detailed JSDoc comments, so setting all this up would not be too difficult: Lines 34 to 44 in 00ce71f
|
Minded to add a PR for some very basic improvements to existing JSDoc 👍 |
Usually what i do is enabling widespread checkjs, this can be done in vscode settings.json or in a {
// The 3 most important one:
"js/ts.implicitProjectConfig.checkJs": true,
// Enable suggestion to complete JSDoc comments.
"javascript.suggest.completeJSDocs": true,
// Preferred path ending with extension (good for both esm & cjs).
"javascript.preferences.importModuleSpecifierEnding": "js",
// Other suggestions useful stuff:
// Complete functions with their parameter signature.
"javascript.suggest.completeFunctionCalls": true,
// Enable auto import suggestions.
"javascript.suggest.autoImports": true
} |
@jimmywarting editor or TypeScript config doesn't get published or used when the package is installed by users. You don't just want type safety for the source code of the package you are authoring, but also for your users consuming the published package. |
It'd be really convenient if the Koa types were distributed with the koa package rather than requiring a separate install of
@types/koa
.I see that requests for a TypeScript rewrite have been closed, but could the types at least be pulled in? It might help keep them in sync as well.
The text was updated successfully, but these errors were encountered: