Skip to content
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

Documentation for UserConfig type definitions doesn't work in ESM #3127

Closed
sentience opened this issue Dec 19, 2023 · 4 comments
Closed

Documentation for UserConfig type definitions doesn't work in ESM #3127

sentience opened this issue Dec 19, 2023 · 4 comments
Labels
bug typescript Type definitions and Typescript issues

Comments

@sentience
Copy link

Operating system

macOS Sonoma 14.2

Eleventy

3.0.0-alpha.2

Describe the bug

The 11ty docs recommend this as the way to get TypeScript-powered autocomplete on the eleventyConfig object:

/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
module.exports = function (eleventyConfig) {
  // …
};

After converting my Eleventy project to ESM per the 3.0 alpha announcement, I found that this autocomplete was no longer working. Updating the type import to reference the actual file path fixes the issue for me:

/** @param { import("@11ty/eleventy/src/UserConfig.js") } eleventyConfig */
export default function (eleventyConfig) {
  // …
};

I'm not an expert in JSDoc, so I can't say whether there's a downside to this approach (other than the increased verbosity and dependency on Eleventy's internals), but it's what I'm using now. Absent a better suggestion, the Eleventy 3.0 docs and migration guide will probably need to mention this necessary change to preserve the previously-documented functionality.

Reproduction steps

  1. Clone https://github.com/sentience/kevinyank.com/tree/demo-esm-autocomplete-broken
  2. npm install
  3. Open .eleventy.js in Visual Studio Code.
  4. Hover over the eleventyConfig parameter on line 9. Note that Visual Studio Code annotates it as having type any.

Expected behavior

The type should be annotated as UserConfig.

Reproduction URL

https://github.com/sentience/kevinyank.com/tree/demo-esm-autocomplete-broken

Screenshots

No response

@rubenwardy
Copy link

#3097

@zachleat
Copy link
Member

Ah, good catch! I’ll fix the export to include userconfig

@oliverpool
Copy link

In my case I had to add .default:

/** @param { import("@11ty/eleventy/src/UserConfig.js").default } eleventyConfig */
export default function (eleventyConfig) {

@zachleat
Copy link
Member

Duplicate of #3097, /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */ works in 3.0.0-alpha.12+

@zachleat zachleat added the typescript Type definitions and Typescript issues label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug typescript Type definitions and Typescript issues
Projects
None yet
Development

No branches or pull requests

4 participants