In typescript, how to do import merge from "lodash/merge"
Actually you can import a single function using the 'lodash.merge'
library
import merge from 'lodash.merge'
const result: any = merge(obj1, obj2)
BUT
You need to add this property to the tsconfig.json "esModuleInterop": true
without this it will not work
[cit] https://github.com/lodash/lodash/issues/3192#issuecomment-411963038
Update
The modern way to do that is to use the individual packages. e.g. for merge
you would install and use lodash.merge
i.e.
import merge from 'lodash.merge'
PS: Ensure
"esModuleInterop": true
is in yourtsconfig.json
as its needed for the ES default import of merge to work.
Old Answer
Cannot find module "lodash/merge". How to solve it
The definitions for TypeScript don't support individual loading of lodash members. So you can only import * as _ from "lodash"
.