-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Type checking and IntelliSense with JSDoc typed js dependencies #29824
Comments
that sounds like a nice solution... currently this needs to be done "manually" e.g. if I want to get the JSDoc types of "include": [
"**/*.js",
"node_modules/<your-package-name>/**/*.js"
],
"exclude": [
"node_modules/!(<your-package-name>)"
] Some more details you can find a the blog bost Type-Safe Web Components with JSDoc is there anything we can do to help? |
Yup, I hate having to put node modules with JSDoc comments in the |
I noticed a bug when using a module that consists of several files that import JSDoc types from other files. When such a project has an |
This is very painful and makes the claim that "typescript supports JSDoc" false in practice. |
We can now generate TypeScript type declaration files for all packages by running `npm run build`. This ensures that TypeScript projects which import Reliability Kit modules will get proper type hinting and will not throw errors during compliation. This is a known issue, and it'd be nice if we didn't have to do it, but it's either this or go wholesale TypeScript which involves a more complex build step and it'd be a large-scale migration. I also still think we shouldn't do it. More context on the issue: * microsoft/TypeScript#19145 * microsoft/TypeScript#29824
We can now generate TypeScript type declaration files for all packages by running `npm run build`. This ensures that TypeScript projects which import Reliability Kit modules will get proper type hinting and will not throw errors during compliation. This is a known issue, and it'd be nice if we didn't have to do it, but it's either this or go wholesale TypeScript which involves a more complex build step and it'd be a large-scale migration. I also still think we shouldn't do it. More context on the issue: * microsoft/TypeScript#19145 * microsoft/TypeScript#29824
This actually can be done with But it also requires a very non-obvious configuration. We can achieve it with the "typesVersions": {
"*": {
"src/*": [
"types/*"
]
}
}, This solves the problem that when you otherwise output the declaration files sibling to the JS files it breaks how the types are resolved in the JS files, so this trick allows placing the declaration files elsewhere instead of as siblings. Here is a project with this configuration: See also the Now, when we run Here's what the published types look like, including declaration source maps: https://unpkg.com/browse/pota@0.14.133/types/ The TLDRIt would be really great to have this working out of the box though, without
Ideally, because we're writing JS+JSDoc, we don't have to run a build at all, and TypeScript would just gather types directly from the JS files (I would not prioritize performance of reading types from JS over it simply working, but making |
Search Terms
JSDoc types dependenies
Suggestion
Possible alternative to #7546: Maybe type checking from JSDoc annotated dependencies can be achieved more easily in a different way. I have created a gist with a demo project that successfully uses a dependency (ol@6.0.0-beta.1 with fully JSDoc typed sources. This works well to get IntelliSense in VS Code for projects authored in pure JavaScript, but requires a not very obvious
jsconfig.json
configuration. Similar configurations (withtsconfig.json
) partially work with TypeScript projects, but are very fragile quite easily, especially in more complex projects. And they only work when the"noEmit": true
option is used.However, it looks like a much lower hanging fruit than making
.d.ts
file generation work from JSDoc annotated JavaScript code (#7546). As the above example shows, it works already, but it should work out of the box and also in more complex configurations with TypeScript.Use Cases
Full type checking and
tsc
support in both JavaScript and TypeScript projects with pure JavaScript dependencies. The dependencies are either JSDoc typed directly or published with their JSDoc typed sources.This has to work without
.d.ts
files, because these cannot be generated from.js
sources, neither withtsc
nor reliably with third party applications.Examples
Two possible scenarios:
class
andextends
keywords are used, which packages don't usually do, because it limits interoperability.So let's assume the latter case is the more common one. If TypeScript would look for a
tsconfig.json
in dependencies (e.g.node_modules/ol/tsconfig.json
), that file could have a config option to point to the annotated sources. Maybe something likeChecklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: