DefinitelyTyped/types/lodash
2020-04-17 15:57:56 -07:00
..
common Update lang.d.ts (#43872) 2020-04-17 15:57:56 -07:00
fp
scripts
ts3.1
v3 Don't hardcode module name in @types/lodash (#43684) 2020-04-17 15:50:09 -07:00
add.d.ts
after.d.ts
ary.d.ts
assign.d.ts
assignIn.d.ts
assignInWith.d.ts
assignWith.d.ts
at.d.ts
attempt.d.ts
before.d.ts
bind.d.ts
bindAll.d.ts
bindKey.d.ts
camelCase.d.ts
capitalize.d.ts
castArray.d.ts
ceil.d.ts
chain.d.ts
chunk.d.ts
clamp.d.ts
clone.d.ts
cloneDeep.d.ts
cloneDeepWith.d.ts
cloneWith.d.ts
compact.d.ts
concat.d.ts
cond.d.ts
conformsTo.d.ts
constant.d.ts
countBy.d.ts
create.d.ts
curry.d.ts
curryRight.d.ts
debounce.d.ts
deburr.d.ts
defaults.d.ts
defaultsDeep.d.ts
defaultTo.d.ts
defer.d.ts
delay.d.ts
difference.d.ts
differenceBy.d.ts
differenceWith.d.ts
divide.d.ts
drop.d.ts
dropRight.d.ts
dropRightWhile.d.ts
dropWhile.d.ts
each.d.ts
eachRight.d.ts
endsWith.d.ts
entries.d.ts
entriesIn.d.ts
eq.d.ts
escape.d.ts
escapeRegExp.d.ts
every.d.ts
extend.d.ts
extendWith.d.ts
fill.d.ts
filter.d.ts
find.d.ts
findIndex.d.ts
findKey.d.ts
findLast.d.ts
findLastIndex.d.ts
findLastKey.d.ts
first.d.ts
flatMap.d.ts
flatMapDeep.d.ts
flatMapDepth.d.ts
flatten.d.ts
flattenDeep.d.ts
flattenDepth.d.ts
flip.d.ts
floor.d.ts
flow.d.ts
flowRight.d.ts
forEach.d.ts
forEachRight.d.ts
forIn.d.ts
forInRight.d.ts
forOwn.d.ts
forOwnRight.d.ts
fp.d.ts
fromPairs.d.ts
functions.d.ts
functionsIn.d.ts
get.d.ts
groupBy.d.ts
gt.d.ts
gte.d.ts
has.d.ts
hasIn.d.ts
head.d.ts
identity.d.ts
includes.d.ts
index.d.ts
indexOf.d.ts
initial.d.ts
inRange.d.ts
intersection.d.ts
intersectionBy.d.ts
intersectionWith.d.ts
invert.d.ts
invertBy.d.ts
invoke.d.ts
invokeMap.d.ts
isArguments.d.ts
isArray.d.ts
isArrayBuffer.d.ts
isArrayLike.d.ts
isArrayLikeObject.d.ts
isBoolean.d.ts
isBuffer.d.ts
isDate.d.ts
isElement.d.ts
isEmpty.d.ts
isEqual.d.ts
isEqualWith.d.ts
isError.d.ts
isFinite.d.ts
isFunction.d.ts
isInteger.d.ts
isLength.d.ts
isMap.d.ts
isMatch.d.ts
isMatchWith.d.ts
isNaN.d.ts
isNative.d.ts
isNil.d.ts
isNull.d.ts
isNumber.d.ts
isObject.d.ts
isObjectLike.d.ts
isPlainObject.d.ts
isRegExp.d.ts
isSafeInteger.d.ts
isSet.d.ts
isString.d.ts
isSymbol.d.ts
isTypedArray.d.ts
isUndefined.d.ts
isWeakMap.d.ts
isWeakSet.d.ts
iteratee.d.ts
join.d.ts
kebabCase.d.ts
keyBy.d.ts
keys.d.ts
keysIn.d.ts
last.d.ts
lastIndexOf.d.ts
lodash-tests.ts
lowerCase.d.ts
lowerFirst.d.ts
lt.d.ts
lte.d.ts
map.d.ts
mapKeys.d.ts
mapValues.d.ts
matches.d.ts
matchesProperty.d.ts
max.d.ts
maxBy.d.ts
mean.d.ts
meanBy.d.ts
memoize.d.ts
merge.d.ts
mergeWith.d.ts
method.d.ts
methodOf.d.ts
min.d.ts
minBy.d.ts
mixin.d.ts
multiply.d.ts
negate.d.ts
noConflict.d.ts
noop.d.ts
now.d.ts
nth.d.ts
nthArg.d.ts
omit.d.ts
omitBy.d.ts
once.d.ts
orderBy.d.ts
OTHER_FILES.txt
over.d.ts
overArgs.d.ts
overEvery.d.ts
overSome.d.ts
package.json
pad.d.ts
padEnd.d.ts
padStart.d.ts
parseInt.d.ts
partial.d.ts
partialRight.d.ts
partition.d.ts
pick.d.ts
pickBy.d.ts
property.d.ts
propertyOf.d.ts
pull.d.ts
pullAll.d.ts
pullAllBy.d.ts
pullAllWith.d.ts
pullAt.d.ts
random.d.ts
range.d.ts
rangeRight.d.ts
readme.md
rearg.d.ts
reduce.d.ts
reduceRight.d.ts
reject.d.ts
remove.d.ts
repeat.d.ts
replace.d.ts
rest.d.ts
result.d.ts
reverse.d.ts
round.d.ts
runInContext.d.ts
sample.d.ts
sampleSize.d.ts
set.d.ts
setWith.d.ts
shuffle.d.ts
size.d.ts
slice.d.ts
snakeCase.d.ts
some.d.ts
sortBy.d.ts
sortedIndex.d.ts
sortedIndexBy.d.ts
sortedIndexOf.d.ts
sortedLastIndex.d.ts
sortedLastIndexBy.d.ts
sortedLastIndexOf.d.ts
sortedUniq.d.ts
sortedUniqBy.d.ts
split.d.ts
spread.d.ts
startCase.d.ts
startsWith.d.ts
stubFalse.d.ts
stubTrue.d.ts
subtract.d.ts
sum.d.ts
sumBy.d.ts
tail.d.ts
take.d.ts
takeRight.d.ts
takeRightWhile.d.ts
takeWhile.d.ts
tap.d.ts
template.d.ts
throttle.d.ts
thru.d.ts
times.d.ts
toArray.d.ts
toFinite.d.ts
toInteger.d.ts
toLength.d.ts
toLower.d.ts
toNumber.d.ts
toPairs.d.ts
toPairsIn.d.ts
toPath.d.ts
toPlainObject.d.ts
toSafeInteger.d.ts
toString.d.ts
toUpper.d.ts
transform.d.ts
trim.d.ts
trimEnd.d.ts
trimStart.d.ts
truncate.d.ts
tsconfig.json
tslint.json
unary.d.ts
unescape.d.ts
union.d.ts
unionBy.d.ts
unionWith.d.ts
uniq.d.ts
uniqBy.d.ts
uniqueId.d.ts
uniqWith.d.ts
unset.d.ts
unzip.d.ts
unzipWith.d.ts
update.d.ts
updateWith.d.ts
upperCase.d.ts
upperFirst.d.ts
values.d.ts
valuesIn.d.ts
without.d.ts
words.d.ts
wrap.d.ts
xor.d.ts
xorBy.d.ts
xorWith.d.ts
zip.d.ts
zipObject.d.ts
zipObjectDeep.d.ts
zipWith.d.ts

Notes for lodash developers

Folder Structure

  • Root
    • index.d.ts: this is the main file that will be imported when people do import _ from "lodash". It references files for the lodash types.
    • fp.d.ts: like index.d.ts, but for the functional programming variant of lodash. See https://github.com/lodash/lodash/wiki/FP-Guide.
    • lodash-tests.ts: contains test cases. Update these as necessary when you make a change.
    • tsconfig.json: usually you shouldn't modify this file. However, if you add a new file, you should probably add it to the files list in tsconfig.json.
    • tslint.json: contains lint rules. The goal is to remove all of the rule overrides and match only the dtslint/dt.json rules.
    • All other files: these exist so people can import individual functions, e.g. import * as flatMap from "lodash/flatMap"
  • common directory: contains the main lodash types, split into multiple files for maintainability reasons. These files are NOT meant to be imported directly - they should only be referenced by index.d.ts.
  • fp directory: contains individual functions for lodash/fp. These files may be imported. You should not modify these scripts directly - you should use a script to re-generate them (see below).
  • scripts directory: contains code generation scripts.
    • Before running any scripts, run npm install in this directory (it contains its own package.json).
    • Most notable script is npm run generate, which re-generates all of the fp files and lowdb wrapper extensions.
  • v3 directory: contains types for lodash v3.

Different ways people might use lodash

  • Importing
    • import * as _ from "lodash"
    • import * as _ from "lodash/fp"
    • import { flatMap } from "lodash"
    • import { flatMap } from "lodash/fp"
    • import * as flatMap from "lodash/flatMap"
    • import * as flatMap from "lodash/fp/flatMap"
    • import * as flatMap from "lodash.flatmap" (requires npm install lodash.flatmap)
    • import _ = require("lodash")
    • import _ from "lodash" (only if esModuleInterop is enabled)
  • Global namespace

Before creating a PR

  • For every function you modify, don't forget to update the corresponding wrapper functions.
  • Re-generate the fp types by opening a terminal in the scripts directory and running npm run generate.
    • Note that this directory has its own package.json, so you'll need to run npm install first if you haven't already.
  • Back at the root directory, do npm run lint lodash and make sure there are no errors.

FAQ

  • I'm fixing a bug in v4. Should I also update the v3 types?
    • In general, no.
  • If the wrapper functions are almost copies of the original functions, shouldn't we auto-generate them like we do for lodash/fp?
    • Good idea! If you have time, submit a PR.
  • When I ran npm run lint lodash, I got an error that looks like <--- Last few GCs --->.
    • Yeah, this error is really annoying. It means that node.js ran out of memory before it could run all of your tests.
      • If you see something like Test with 2.6 before that error, it means that there's an error in an older version of typescript. The hard part is figuring out what the error is.
    • The general procedure for diagnosing these errors is:
      1. Delete half of the tests in lodash-tests.ts (either the top half or the bottom half).
      • If you delete the top half, don't delete the important stuff like interface AbcObject.
      1. Run npm run lint lodash.
      2. If it succeeds, add that half back and delete the other half.
      3. If it fails with a GC error, delete half of the remaining tests.
      • Note: If both halves succeed on their own, then the tests are probably just consuming too much memory. Try simplifying them until they pass.
      1. Repeat steps 1-4 until it gives you the real error message. Usually it's something obscure that only happens in TS 2.3/T.4, so commenting/modifying the test is usually the best solution.