🌐
npm
npmjs.com › package › @types › lodash
@types/lodash - npm
February 23, 2026 - TypeScript definitions for lodash. Latest version: 4.17.24, last published: a month ago. Start using @types/lodash in your project by running `npm i @types/lodash`. There are 11410 other projects in the npm registry using @types/lodash.
      » npm install @types/lodash
    
🌐
Carl Rippon
carlrippon.com › using-lodash-debounce-with-react-and-ts
Using Lodash debounce with React and TypeScript
December 22, 2021 - How to install and use the debounce function from Lodash in a React and TypeScript app
Discussions

Importing lodash into angular2 + typescript application
I am having a hard time trying to get the lodash modules imported. I've setup my project using npm+gulp, and keep hitting the same wall. I've tried the regular lodash, but also lodash-es. The lodas... More on stackoverflow.com
🌐 stackoverflow.com
How to debounce Lodash call to fetch in Typescript properly?
I'm relatively new to React & Typescript/JS and am trying to understand how to debounce a call to a promise properly. There's a button to increment/decrement a desired purchase quantity and only after a certain period of time do I want to actually execute the call to the backend API, to avoid the user just repeatedly hitting the +/- buttons and spamming the server. import debounce from 'lodash... More on stackoverflow.com
🌐 stackoverflow.com
How to import lodash in a typescript library package?
I'd like to centralize my generic most-used (typescript) functions in a Util package which I can reuse across my projects. Turned out more difficult than expected. This package is not going to be More on stackoverflow.com
🌐 stackoverflow.com
Question - Importing single function with typescript, lodash, jest
I am writing a library using typescript, jest and lodash and I would like to ship it as 2 modules - commonjs (for webpack 1) and with es2015 modules (for webpack 2 with tree-shaking). What i tried:... More on github.com
🌐 github.com
14
June 7, 2017
JavaScript library in the functional programming paradigm
Lodash is a JavaScript library which provides utility functions for common programming tasks using the functional programming paradigm. Lodash is a fork of Underscore.js. It joined the Dojo Foundation in 2013, and … Wikipedia
Factsheet
Lodash°
Original author John-David Dalton
Factsheet
Lodash°
Original author John-David Dalton
🌐
Lodash
lodash.com
Lodash
Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
🌐
My Memory
putridparrot.com › blog › using-lodash-in-typescript
Using lodash in TypeScript | My Memory
Was trying to use lodash and couldn’t seem to get Visual Code to build my TypeScript files correctly, so here’s how to get it working…
🌐
Medium
sanjanahumanintech.medium.com › lodash-library-usage-in-javascript-typescript-cafc82818dd5
Lodash Library usage in Javascript/typescript | by Sanjana Human In Tech | Medium
November 26, 2023 - TypeScript (with Lodash): import _ from 'lodash'; const fruits = ['apple', 'banana', 'orange', 'grape', 'apple']; const groupedByFruit = _.groupBy(fruits); console.log(groupedByFruit); // { apple: 2, banana: 1, orange: 1, grape: 1 } Thank you for reading this article! Don’t forget to clap only if you think I deserve it👏 and buy me a coffee. If you have any queries related to ReactNative, I’m always happy to help you.
🌐
CodeSandbox
codesandbox.io › s › 1kjh8
react-typescript-lodash - CodeSandbox
December 27, 2023 - react-typescript-lodash by anpleenko using @types/lodash, lodash, qs, react, react-dom, react-scripts
Published   Jan 12, 2021
Author   anpleenko
Top answer
1 of 16
508

Here is how to do this as of Typescript 2.0: (tsd and typings are being deprecated in favor of the following):

$ npm install --save lodash

# This is the new bit here: 
$ npm install --save-dev @types/lodash

Then, in your .ts file:

Either:

import * as _ from "lodash";

Or (as suggested by @Naitik):

import _ from "lodash";

I'm not positive what the difference is. We use and prefer the first syntax. However, some report that the first syntax doesn't work for them, and someone else has commented that the latter syntax is incompatible with lazy loaded webpack modules. YMMV.

Edit on Feb 27th, 2017:

According to @Koert below, import * as _ from "lodash"; is the only working syntax as of Typescript 2.2.1, lodash 4.17.4, and @types/lodash 4.14.53. He says that the other suggested import syntax gives the error "has no default export".

2 of 16
70

Update September 26, 2016:

As @Taytay's answer says, instead of the 'typings' installations that we used a few months ago, we can now use:

npm install --save @types/lodash

Here are some additional references supporting that answer:

  • https://www.npmjs.com/package/@types/lodash
  • TypeScript typings in NPM @types org packages

If still using the typings installation, see the comments below (by others) regarding '''--ambient''' and '''--global'''.

Also, in the new Quick Start, config is no longer in index.html; it's now in systemjs.config.ts (if using SystemJS).

Original Answer:

This worked on my mac (after installing Angular 2 as per Quick Start):

sudo npm install typings --global
npm install lodash --save 
typings install lodash --ambient --save

You will find various files affected, e.g.

  • /typings/main.d.ts
  • /typings.json
  • /package.json

Angular 2 Quickstart uses System.js, so I added 'map' to the config in index.html as follows:

System.config({
    packages: {
      app: {
        format: 'register',
        defaultExtension: 'js'
      }
    },
    map: {
      lodash: 'node_modules/lodash/lodash.js'
    }
  });

Then in my .ts code I was able to do:

import _ from 'lodash';

console.log('lodash version:', _.VERSION);

Edits from mid-2016:

As @tibbus mentions, in some contexts, you need:

import * as _ from 'lodash';

If starting from angular2-seed, and if you don't want to import every time, you can skip the map and import steps and just uncomment the lodash line in tools/config/project.config.ts.

To get my tests working with lodash, I also had to add a line to the files array in karma.conf.js:

'node_modules/lodash/lodash.js',
Find elsewhere
🌐
MoldStud
moldstud.com › articles › developers faq › lodash developers questions › how to use lodash in a react application?
How to use Lodash in a React application? | MoldStud
August 1, 2024 - Answer: Yes, Lodash is compatible with TypeScript and you can use type definitions to ensure type safety when working with Lodash functions in React components.
Top answer
1 of 1
1

I found two three possible working scenarios:

  1. Use TSdx, the Zero-config CLI for TypeScript package development. https://tsdx.io/
  2. Use lodash-es instead (but note that chains are not working in lodash-es!). Explanation below. This however still gives Jest errors when this library is imported in another library, and tested there.
  3. Use vitest instead. Vitest is largely compatible with the Jest api. After installing Vitest, everything simply worked, without any configuration. The only thing to do is to add import { assert, expect, test } from 'vitest' to your tests. If you have just started, and only have simple tests, they simply worked without any changes (YMMV). In addition, both lodash and lodash-es worked fine.

A better answer would include a scenario that uses "plain" lodash, or explains why lodash-es is actually a good thing. From what I'm reading in various posts is that lodash-es has several drawbacks (results in a larger bundle size, chains don't work).

Here is a working setup with (I think) sensible defaults. This library is for internal use, and I run Node 18, so I use a high target version here.

package.json

{
  "name": "@vexna/util",
  "version": "1.0.0",
  "description": "Generic utilities, uses lodash",
  "private": true,
  "type": "module",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "sideEffects": false,
  "scripts": {
    "build": "rimraf dist && tsc && rollup -c rollup.config.js",
    "test": "node test/spec",
    "pretest": "npm run build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@rollup/plugin-typescript": "^11.0.0",
    "@types/lodash-es": "^4.17.6",
    "lodash-es": "^4.17.21",
    "rimraf": "^4.1.2",
    "rollup": "^3.12.1",
    "typescript": "^4.9.5"
  },
  "files": [
    "dist"
  ],
  "peerDependencies": {
    "lodash": "^4.17.21"
  }
}

tsconfig.ts

{
    "compilerOptions": {
      "module": "es2022",
      "moduleResolution": "node",
      "outDir": "dist",
      "declaration": true,
      "sourceMap": true,
      "esModuleInterop": true,
      "allowSyntheticDefaultImports": true,
      "forceConsistentCasingInFileNames": true,
      "lib": ["es2022", "DOM", "DOM.Iterable"],
      "target": "es2022",
      "skipLibCheck": true,
      "strict": true,
      "exactOptionalPropertyTypes": true,
      "noImplicitAny": true,
      "noImplicitThis": true,
      "checkJs": true
    },
    "include": ["./src/**/*.ts"]
}

rollup.config.js

import typescript from '@rollup/plugin-typescript'
const input = ["src/index.ts"]

export default [
    {
        input,
        plugins: [
            typescript()],
        output: [
            {
                dir: "dist",
                sourcemap: true,
            }
        ],
        external: ['lodash-es'],
    }
]

The output has lodash entirely externalized, so very small bundle! As a precaution, I added "lodash": "^4.17.21" to the "peerDependencies". This is a little odd cause it's a mismatch with devDependencies (which uses the -es), but this seems fine. YMMV.

In the library code, you can import the lodash functions like so:

import { now, random, padStart } from "lodash-es"

A project that consumes this library must have lodash, and can import like so:

import { createUid } from '@vexna/util'
🌐
xjavascript
xjavascript.com › blog › lodash-react-typescript
Mastering Lodash, React, and TypeScript: A Comprehensive Guide — xjavascript.com
Lodash provides useful utility functions for data manipulation and performance optimization, React offers a powerful way to build user interfaces, and TypeScript adds static typing for better code quality.
🌐
GitHub
github.com › lodash › lodash › issues › 3192
Question - Importing single function with typescript, lodash, jest · Issue #3192 · lodash/lodash
June 7, 2017 - I ended up with import * as cloneDeep from 'lodash.clonedeep'; which finally worked. Is this the only way to do this? Am I missing something? If it's more typescript related problem, feel free to close this. Reactions are currently unavailable · No one assigned ·
Author   vojty
🌐
Reddit
reddit.com › r/typescript › a typescript-first alternative to lodash/underscore
r/typescript on Reddit: A Typescript-first alternative to Lodash/Underscore
January 20, 2023 -

EDIT: I forgot to put a question mark at the end of the title. Whoops!

I understand that both libraries have "@types/..." that can easily be downloaded. Still, some corners of the library would have been better designed if they were initially built in Typescript rather than tacking on a.d.ts file later.

I am starting a new project and would like to know if any alternatives have been developed recently.

🌐
Aguidehub
aguidehub.com › blog › 2023-04-13-how-to-install-and-use-lodash-in-react-js
how to install and use lodash in react js?
April 13, 2023 - Example of change background color of mui table in React js with step by step tutorial - aGuideHubMarch 21, 20244 minsReactHow to set max width of mui table in react js · Example of set max width of mui table in React js with step by step tutorial - aGuideHubMarch 20, 20244 minsReactHow to ...
🌐
Delft Stack
delftstack.com › home › howto › typescript › lodash typescript
How to Use Lodash in TypeScript | Delft Stack
February 2, 2024 - Lodash also allows us to get the random numbers using a simple function _.random(). We can provide one or two parameters in this function. If we provide only one parameter, it will take the starting point from 0. Let’s go through an example and try to generate a random number between 0 to 100 and 50 to 100. # typescript const _ = require("lodash"); let randNum = _.random(100); console.log(randNum); randNum = _.random(50, 100); console.log(randNum);
🌐
GitHub
github.com › typicode › react-lodash
GitHub - typicode/react-lodash: ⚛️ 🔧 Lodash as React components
The answer to the latter is obviously yes (otherwise, this repo wouldn't exist 😉). react-lodash is therefore a 1:1 mapping with lodash API and all components are generated using npm run generate.
Starred by 352 users
Forked by 18 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
npm
npmjs.com › package › lodash
lodash - npm
February 20, 2021 - // Load the full build. var _ = require('lodash'); // Load the core build. var _ = require('lodash/core'); // Load the FP build for immutable auto-curried iteratee-first data-last methods. var fp = require('lodash/fp'); // Load method categories. var array = require('lodash/array'); var object = require('lodash/fp/object'); // Cherry-pick methods for smaller browserify/rollup/webpack bundles.
      » npm install lodash
    
Published   Jan 21, 2026
Version   4.17.23
Author   John-David Dalton