wes-goulet ยท GitHub

Hi ๐Ÿ‘‹ - long time listener, first time caller!

I like to type my javascript files using JSDoc comments. Thanks to an excellent contribution this is possible for the .eleventy.js config file ๐ŸŽ‰ . However, it can be more discoverable/easier with a small tweak ๐Ÿ˜„ ... that's where this here PR comes.

As discussed in #2033 the the way for 11ty consumers to get types is to reach into the 11ty package internals and find the type you want. That's less than ideal for consumers and a bit fragile (if the file ever moves with a refactor or whatnot).

So this PR does 2 things:
1๏ธโƒฃ - Makes an index.d.ts declaration file that can export types
2๏ธโƒฃ - updates the package.json "types" property with the path to that type declaration file

So now a consuming project can import directly from the eleventy package without reaching into it to a specific file path:

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

This PR just starts with adding the UserConfig to get it up and running, but additional types can be exported from index.d.ts over time.

As a personal preference thing, I like to use typedef's to pull in all my dependency types at the top of the file, like so ๐Ÿ‘‡

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

Read the original on github.com โ†—