How to add an ad to an existing object (text input) in typescript

The latest version of lodash now has several new features. For example: https://lodash.com/docs#nth .

But lodash typing is for the old version and does not have these features.

import _ = require('lodash');

How can I add an declaration of these functions to an object _?

+1
source share
1 answer

If you check your typing file, you will see the main LoDashStatic interface, which you can expand:

import old = require('lodash')

interface LodashExt extends old.LoDashStatic {
    nth(n: Array<any>, i: number) : LodashExt
    // . . .
}

var _ = <LodashExt>old

_.add(1, 2)

_.nth(['a', 'b', 'c', 'd'], 2)

This should be enough for simple cases. You might want to place the above declarations in a module and simply export the new _ value.

0
source

Source: https://habr.com/ru/post/1688385/


All Articles