🌐
npm
npmjs.com › package › @types › lodash
@types/lodash - npm
1 month ago - 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 11413 other projects in the npm registry using @types/lodash.
      » npm install @types/lodash
    
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
Initial release April 23, 2012; 13 years ago (2012-04-23)
Factsheet
Lodash°
Original author John-David Dalton
Initial release April 23, 2012; 13 years ago (2012-04-23)
🌐
Lodash
lodash.com
Lodash
Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
Discussions

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
A Typescript-first alternative to Lodash/Underscore
Check out ‘radash’ on npm. It advertises itself as a ‘modern lodash’ lol. It has almost everything lodash has, written with first-class TS. Unfortunately, something to keep in mind is that the maintainer of the project hasn’t merged any pull requests or fixed any issues in the last couple of months. Which couldd be a problem based on your needs. More on reddit.com
🌐 r/typescript
41
42
January 20, 2023
[@types/lodash] Issue with lodash typings causing TypeScript compilation error
Hi all I'm encountering an error related to the Lodash typings while trying to compile my TypeScript project. The issue seems to be with the compatibility between the Lodash typings and TypeScr... More on github.com
🌐 github.com
2
4
July 7, 2023
ts node - How to use lodash-es in typescript correctly? - Stack Overflow
I need to use lodash-es in my typescript project, but I can't configure it correctly, it always reports errors like SyntaxError: Unexpected identifier hello.ts import upperCase from 'lodash-es/ More on stackoverflow.com
🌐 stackoverflow.com
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'
🌐
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.

🌐
Lodash
lodash.com › docs
Lodash Documentation
Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with three arguments: (value, index|key, collection). Many lodash methods are guarded to work as iteratees for methods like _.every, _.filter, _.map, _.mapValues, _.reject, and _.some.
🌐
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 - Lodash is a popular utility library for JavaScript that provides a wide range of helpful functions to make working with arrays, objects, strings, and other data types more convenient and efficient.
Find elsewhere
🌐
My Memory
putridparrot.com › blog › using-lodash-in-typescript
Using lodash in TypeScript | My Memory
May 12, 2019 - 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…
🌐
DEV Community
dev.to › oooopsitsme › why-you-should-use-lodash-es-in-your-typescript-projects-153n
Why You Should Use `lodash-es` in Your TypeScript Projects - DEV Community
August 23, 2024 - Lodash has excellent TypeScript support, with types available out of the box. This makes working with lodash-es a breeze when using TypeScript.
🌐
UNPKG
app.unpkg.com › @types › lodash@4.14.162
types/lodash
TypeScript definitions for Lo-Dash · DefinitelyTyped/DefinitelyTyped · 2 folders, 306 files · DefinitelyTyped/DefinitelyTyped · Latest: 4.17.21 ·
🌐
Total TypeScript
totaltypescript.com › workshops › advanced-typescript-patterns › external-libraries › navigating-lodash-s-type-definitions
Navigating Lodash's Type Definitions | Total TypeScript
June 8, 2023 - 0:00 In the next exercise, the one after this, we're going to be diving into the types of lodash. I want to give you some tools to help you navigate this library. Now, this is the main way that you import from lodash. You can also do things like lodash groupBy, or things like this, or grab individual functions from it.
🌐
StackBlitz
stackblitz.com › edit › typescript-lodash-playground
Typescript Lodash Playground - StackBlitz
Stackblitz playground to test lodash with typescript. Just fork it and play around
🌐
Ben Ilegbodu
benmvp.com › blog › understanding-typescript-generics-lodash-functions
Understanding TypeScript generics through lodash functions | Ben Ilegbodu
August 22, 2021 - It's used as the default callback function in many of the lodash functions. It takes any type of value and returns back that value. So if we pass in a string value, we get back that same string value. Or if we pass in some object type, we get back that same object of the same type. So how do we use TypeScript to type it?
🌐
CodeSandbox
codesandbox.io › s › js-typescript-lodash-qfkon
JS TypeScript (lodash) - CodeSandbox
September 8, 2021 - TypeScript + Jest base sandbox.
Published   Sep 02, 2021
Author   coltanium13
🌐
Bennadel
bennadel.com › blog › 3328-fixing-lodash-typescript-errors-by-upgrading-types-lodash-in-node-or-webpack.htm
Fixing Lodash TypeScript Errors By Upgrading @types/lodash In Node Or Webpack
April 21, 2020 - Ben Nadel shares a set of TypeScript error messages that he was getting when attempting to create a proxy method around Lodash. The fix was to upgrade TypeScript and the Definitely Typed "@types/lodas
🌐
PlayCode
playcode.io › lodash
Lodash Editor - Utility Functions - PlayCode
Use Lodash utilities instantly. Array, object, string helpers. AI suggests Lodash methods.