-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
JSDoc type annotations on module.exports assignments not type checked #47107
Labels
Domain: JSDoc
Relates to JSDoc parsing and type generation
Experience Enhancement
Noncontroversial enhancements
Suggestion
An idea for TypeScript
Milestone
Comments
I've run into the same problem with different details. On TypeScript 4.9.5, typing This /** @type {import("gatsby").GatsbyBrowser} */
module.exports = {
shouldUpdateScroll: ({ routerProps }) =>
routerProps.location.state?.shouldUpdateScroll ?? true,
}; This one does not: const { RouteUpdateProgress } = require("./src/components/RouteUpdateProgress");
/** @type {import("gatsby").GatsbyBrowser} */
module.exports = {
shouldUpdateScroll: ({ routerProps }) => // Binding element 'routerProps' implicitly has an 'any' type.
routerProps.location.state?.shouldUpdateScroll ?? true,
wrapPageElement: ({ element }) => ( // Binding element 'element' implicitly has an 'any' type.
<RouteUpdateProgress>{element}</RouteUpdateProgress>
),
}; Workaround is same as OP. |
Ah looks like this issue is also similar to (or maybe even the same as) my issue over here: |
This was referenced Apr 19, 2023
36degrees
added a commit
to alphagov/govuk-design-system
that referenced
this issue
Apr 11, 2024
There’s an issue with the TypeScript compiler that prevents direct assignments to `module.exports` being type checked. [1] We can work around this by assigning the config to a const first, then exporting it as a second step. This means that the invalid config is correctly flagged when running `npm run lint:types` and in VS Code. [1]: microsoft/TypeScript#47107
daniellockyer
added a commit
to TryGhost/Ghost
that referenced
this issue
May 7, 2024
- this adds a simple set of types to the @tryghost/api-framework package that should describe all of the keys available on a controller, and then rolls it out to all API controllers - unfortunately, due to microsoft/TypeScript#47107, we have to split apart `module.exports` into a variable assignment in order for type-checking to be done - the main benefit of this is that `frame` is now typed, and editors understand what keys are available, so intellisense works properly
daniellockyer
added a commit
to TryGhost/Ghost
that referenced
this issue
May 7, 2024
- this adds a simple set of types to the @tryghost/api-framework package that should describe all of the keys available on a controller, and then rolls it out to all API controllers - unfortunately, due to microsoft/TypeScript#47107, we have to split apart `module.exports` into a variable assignment in order for type-checking to be done - the main benefit of this is that `frame` is now typed, and editors understand what keys are available, so intellisense works properly
daniellockyer
added a commit
to TryGhost/Ghost
that referenced
this issue
May 7, 2024
- this adds a simple set of types to the @tryghost/api-framework package that should describe all of the keys available on a controller, and then rolls it out to all API controllers - unfortunately, due to microsoft/TypeScript#47107, we have to split apart `module.exports` into a variable assignment in order for type-checking to be done - the main benefit of this is that `frame` is now typed, and editors understand what keys are available, so intellisense works properly
daniellockyer
added a commit
to TryGhost/Ghost
that referenced
this issue
May 7, 2024
- this adds a simple set of types to the @tryghost/api-framework package that should describe all of the keys available on a controller, and then rolls it out to all API controllers - unfortunately, due to microsoft/TypeScript#47107, we have to split apart `module.exports` into a variable assignment in order for type-checking to be done - the main benefit of this is that `frame` is now typed, and editors understand what keys are available, so intellisense works properly
daniellockyer
added a commit
to TryGhost/Ghost
that referenced
this issue
May 7, 2024
- this adds a simple set of types to the @tryghost/api-framework package that should describe all of the keys available on a controller, and then rolls it out to all API controllers - unfortunately, due to microsoft/TypeScript#47107, we have to split apart `module.exports` into a variable assignment in order for type-checking to be done - the main benefit of this is that `frame` is now typed, and editors understand what keys are available, so intellisense works properly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Domain: JSDoc
Relates to JSDoc parsing and type generation
Experience Enhancement
Noncontroversial enhancements
Suggestion
An idea for TypeScript
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Adding a
@type
JSDoc annotation tomodule.exports
should type check like it does in other contexts.📃 Motivating Example
Currently, given the following
blah/some-type.ts
:...this doesn't type check:
...but this does, with some extra steps:
This is similar to #27327, but a simple thing like adding a
@type {string}
tomodule.exports
does work. An imported type does not.💻 Use Cases
We have a CommonJS JS config file that we'd like to enable users to type check. The expected way you'd think you'd add a type annotation to it doesn't work.
The text was updated successfully, but these errors were encountered: