-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Configuration API (UserConfig) types, TypeScript mega issue for 3.0 #3097
Comments
This doesn't work for me: import { UserConfig } from "@11ty/eleventy"; I need to do: import UserConfig from "@11ty/eleventy/src/UserConfig.js";
|
see also #3127 |
#3060 removed the .d.ts file to rely on JSDoc entirely, but the .d.ts had been exporting UserConfig (https://github.com/11ty/eleventy/blob/ecd0579a2dded6939510b7c23841388b26eb6d16/src/index.d.ts) and the issue now that is UserConfig isn't exported anywhere else. Would the fix be to export it here? |
Agree. I have |
You don't have to do that, can't you just use it like |
Unfortunately, no... Today I migrated to a new version. I'm so happy that the number of cjs files is decreasing in my projects 🎉 After migration, I encountered two issues.
As I mentioned earlier, my project is configured in a way that TypeScript performs checks on all When TypeScript encounters an import of a package that has no types, it suggests two solutions:
I think before migrating to ESM, this was a rare problem, as I mentioned, many linters ignored |
While migrating to 11tyv3.0.0-alpha.5, the JSDoc comments stopped working for me. It seems that in ESM, you have to explicitly specify the default export. /** @param { import("@11ty/eleventy").UserConfig } eleventyConfig */ ❌
/** @param { (import("@11ty/eleventy/src/UserConfig").default) } eleventyConfig */ ✅ this works fine as well: /**
* @typedef {import('@11ty/eleventy/src/UserConfig').default} EleventyConfig
* @typedef {import('@11ty/eleventy/src/defaultConfig').defaultConfig} EleventyReturnValue
* @type {(eleventyConfig: EleventyConfig) => EleventyReturnValue}
*/ |
See #3291 |
Closing this but would appreciate further confirmation! |
I have
|
@tbroyer (and @what1s1ove), I just tested /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default function (eleventyConfig) { Here's a minimal stackblitz link to confirm: https://stackblitz.com/edit/github-7xpr1h-tbkpjx?file=.eleventy.js Maybe you can share a minimal repro if it's not working for you? If you have a custom |
Got it: this is Because 3.0.0-alpha.14 had a Should a |
Spent some time looking into this and found a few things worth noting: v3.0.0-alpha.14 failed
In v3.0.0-alpha.14 Irrespective of The The previous approach worked better only because it exported import UserConfig from "./src/UserConfig.js";
export { UserConfig }; That said, I think it’d be useful to have IDE autocomplete and I’ve filed the Eleventy.js work at #3383. |
Alright I have a bit more clarity on this now. The previous
The good part of this exploration is that I’m well educated on the topic now and I’m not opposed to including We’ll keep the existing So, TL;DR I do plan to merge #3384 in service of the long term goal of shipping We’ll continue to recommend folks use https://www.11ty.dev/docs/config/#type-definitions for IDE autocomplete. If I’ve missed something important here, please let me know! |
Would you ever consider writing Eleventy in TS itself? And then compiling down to JS with generated type definition files? |
@uncenter No, probably not. TypeScript can export |
Just some clarification on the history here, since it’s been a bit all over the place and it’s worth documenting at the very least for future me (sorry folks, I’m more educated on TypeScript now 😭).
|
You can (technically and unofficially) use TypeScript for the main configuration (e.g.
Essentially, the Unfortunately, since the emitted Use |
*sneaks #582 as the original PR in |
What could be an option: Following node's lead and have a package in DefinitelyTyped. For example, I spotted DefinitelyTyped/DefinitelyTyped#69010 Documentation: https://github.com/DefinitelyTyped/DefinitelyTyped#how-can-i-contribute |
Having a DefinitelyTyped package would be a good holdover, but in what I've learned so far about TS it's more terse if .d.ts files can be installed along with the package. I'd say if it's possible for types to be maintained centrally without having to rely on another package, use a community solution like I also saw another option get mentioned over on #3296: expose a |
FWIW 11ty.ts is probably the most complete and well typed solution available (currently) in this eco. The There is also the matter of plugins which a lot of folks seem to forget. 11ty.ts will auto-type plugins that expose declarations using a typical syntactical structure of plugin parameters by cherry-picking index 1 of the argument order. |
@panoply does 11ty.ts support 11ty v3? |
I have only just upgraded locally. Even though it's lacking some of the v3 API features, it comes with vast majority of the API already cooked so v3 API is by default already largely supported minus some of the new methods available and deprecation notices. If I get some time tomorrow I'll update and bring support. |
@briancarbone I never thanked you for this suggestion. I searched for weeks for a solution to get TypeScript to pick up Eleventy's JSDoc comments so I could use them in my plugin and this suggestion was what did it! It might be possible to import the types directly without having to set up Typescript like this, EDIT: Yes, subpath exports will allow Typescript to import a module directly, if declared. |
(This one is just a reminder for me)
See: https://www.11ty.dev/docs/config/#type-definitions
Pre-alpha I can confirm that v9 (ESM) of
eleventy-base-blog
with npm installed viafile:../eleventy
works fine but I want to remind myself to check post-publish too.The text was updated successfully, but these errors were encountered: