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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lodash] type definitions don鈥檛 support auto-imports #38787
Comments
I'm not an expert in how the module system works so I'm not entirely sure what the solution is here. I'm pretty sure that it was done this way before That said, lodash is a CommonJS package, so the typings need to reflect that. However, there is a separate package ('lodash-es') which has all the same functions, but uses ES6 modules instead of CommonJS - do auto-imports work for that package? |
FWIW, my testing so far has been without esModuleInterop or allowSyntheticDefaultImports, but I think there may have been other related changes to the module system in the past. My assumption going into this is that a lot of care was put into designing the typings the way they are now, and things are probably going to be more complicated than they seem, but maybe there are new opportunities we can explore.
Yes! I thought I remembered some alternative like this. Good to know.
Agreed. I think the conventional way to represent this would be like declare namespace _ {
function add(x: number, y: number): number;
// ...
}
export = _; ...and now I realize the problem, probably the singular motivation for using an interface with members. You need the export to be callable ( |
Apropos of nothing, I think the |
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
馃憢 Hello from the TypeScript team.
While investigating microsoft/TypeScript#31763, I discovered that individual lodash functions are actually written as methods on the
LoDashStatic
interface. So when a user writesthis is modeled as destructuring a method from a CommonJS export. We allow users to write this because it tends to work with bundlers and other ES module interop tools, but it鈥檚 a little iffy spec-wise, and we don鈥檛 offer auto-imports for members. Doing so would essentially be equivalent to something like this:
It would be highly unusual to import members (especially methods) via destructuring, but that鈥檚 how the lodash typings are currently modeled.
I know there鈥檚 a build system and perhaps there are constraints and motivations around that, but it would be great if we could find some way to write each function as an exported function of a module or namespace instead of (or, in addition to, if necessary) an interface member.
Apologies if this has been discussed before, but I couldn鈥檛 find anything. Semi-related was #38326.
Pinging @bczengel @chrootsu @stepancar @aj-r @e-cloud @thorn0 @jtmthf @DomiR @WilliamChelman for thoughts, ideas, and maybe help implementing if possible 馃専 Thanks all!
The text was updated successfully, but these errors were encountered: