Importing lodash in a Typescript project rises an editor error
See original GitHub issueI’m trying to use lodash inside a Typescript, but so far I have been unable to do so. The main issue seems to be related to Typescript typing system.
dependencies:
lodash@4.17.5
@types/lodash@4.14.104
Error: Property '
any lodash property' does not exist on type 'LoDashStatic'.
- I try to uninstall lodash, and install typing module first, but I did not solve the issue.
- I try
import * as _ from 'lodash'
andimport _ from 'lodash'
. Neither solves the error. - Using
import * as _ from 'lodash'
does not even run the code. - Using
import _ from 'lodash'
does run the code, but the error still in the editor.
I also notice that there is no errors in the console when running the application. I don’t know if that’s by design, but it should say something.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Fixing Lodash TypeScript Errors By Upgrading @types/lodash ...
My main file would then import this lodash-extended module and try to use it: // Import the core node services. import ...
Read more >typescript fails to import lodash - Stack Overflow
I have a project that uses typescript and runs in node. I have lodash in my dependencies of the package.json installed.
Read more >A Complete Guide to Using TypeScript in Node.js - Better Stack
A Complete Guide to Using TypeScript in Node.js · Step 1 — Downloading the demo project · Step 2 — Installing and configuring...
Read more >PhpStorm - Code Inspections in JavaScript and TypeScript
You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S . DOM...
Read more >rollup.js
Importing CommonJS · Publishing ES Modules ... reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@michaeljota Yes now I see. The editor shows a red mark because it does not recognize the lodash import for TypeScript. Adding the types does not work; it just shifts the error to the left portion of the import. To get good results, with the style of importing individual operators, I had to:
lodash-es
(add the NPM dependency, and change the import)@types/lodash-es
you can see it in use here:
https://stackblitz.com/edit/github-av3nlg?file=src/app/reddit-search/reddit-image-search.service.ts
While unfortunate, I don’t know of a way to avoid it for this. I think there is a chasm in thinking between two different groups of NPM package creators
lodash-es
instead oflodash
.I hope the newer style gains popularity.
Please see my comment in #338 … you can use
lodash-es
instead.