-
-
Notifications
You must be signed in to change notification settings - Fork 491
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 😭).
|
(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: