Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In typescript, how to do import merge from "lodash/merge"

With es6, I can import just one function from a library to minimise the whole bundle, like:

import merge from "lodash/merge"

However, in typescript, the above sentence will cause a compile error: Cannot find module "lodash/merge". How to solve it?

like image 320
Ron Avatar asked Feb 07 '23 12:02

Ron


1 Answers

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

like image 134
Kevlar Avatar answered Feb 11 '23 01:02

Kevlar