Skip to content

Using lodash method categories #11682

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

Closed
alisabzevari opened this issue Oct 17, 2016 · 4 comments
Closed

Using lodash method categories #11682

alisabzevari opened this issue Oct 17, 2016 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@alisabzevari
Copy link
Contributor

TypeScript Version: nightly (2.1.0-dev.20161017)

I wanted to use lodash method categories. Here is the code I wrote:

import assign from "lodash/assign";
var myVar = assign({}, {foo:"foo"}, {bar:"bar"});

Expected compiled result:

"use strict"
const assign_1 = require("lodash/assign");
var myVar = assign_1({}, {foo:"foo"}, {bar:"bar"});

Actual compiled result:

"use strict"
const assign_1 = require("lodash/assign");
var myVar = assign_1.default({}, {foo:"foo"}, {bar:"bar"});

Some notes:

  • I am using @types/lodash and the definition of assign is:
declare module "lodash/assign" {
   const assign: typeof _.assign;
   export = assign;
}
  • I found out if I remove allowSyntheticDefaultImports and change import * as assign from "lodash/assign";, it will work.
@aluanhaddad
Copy link
Contributor

That is what allowSyntheticDefaultImports is designed to do, model the behavior of loaders or transpilers that ease the consumption of commonjs modules from ES6 modules by mapping export = x that is module.exports = to export default x.

@alisabzevari
Copy link
Contributor Author

@aluanhaddad Yes, exactly. But when you have this switch, the code would not compile correctly.

@RyanCavanaugh
Copy link
Member

import assign from "lodash/assign";

This is unambiguously an import of the default member of the module.

Regarding using import * as with a function, see http://stackoverflow.com/questions/39415661/why-cant-i-import-a-class-or-function-with-import-as-x-from-y

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Oct 19, 2016
@alisabzevari
Copy link
Contributor Author

alisabzevari commented Oct 19, 2016

@RyanCavanaugh Thanks for reply. Maybe I am confused in module standard definitions but expected behaviour for me is that turning on the 'allowSyntheticDefaultImports' switch should enable me to work with non-standard way of importing a module. But it doesn't work on lodash!
Correct me if I am wrong.

@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants