绝对类型的Lodash [英] DefinitelyTyped Lodash

查看:107
本文介绍了绝对类型的Lodash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从lodash导入单个函数,同时保留键入内容.像这样:

I want to import single function from lodash while preserving typings. Such as this:

import invokeMap from 'lodash/invokeMap';

但似乎我不能这样做.编译器说没有模块lodash/invokeMap.没错- DefinitelyTyped 仅声明lodash的顶级模块,因此我只能导入整个包.但是我只想导入一个函数.

But it seems that I cannot do so. Compiler says that there is no module lodash/invokeMap. It's correct — DefinitelyTyped declares only top-level module for lodash, so I can import only the whole package. But I want to import only one function.

是否可以只导入有关lodash的类型信息,而不导入lodash本身?

Is there a way to import only typings information about lodash without importing lodash itself?

以下是我的解决方法计划.我想使用标准的CommonJS require函数导入没有类型信息的必要函数,然后将类型转换为它:

Below is my workaround plan. I want to use standard CommonJS require function to import the necessary function without types information and then cast type onto it:

declare var require;

var invokeMap: _.invokeMap = require('lodash/invokeMap');
               ^^^^^^^^^^^
               Here I want to cast proper type from DefinitelyTyped,
               but how to reach that `invokeMap` typings alone?

推荐答案

使用当前键入的lodash,它应该可以像您之前尝试过的那样工作:

With the current typings lodash this should work as you tried it before:

import invokeMap from 'lodash/invokeMap';

只需安装当前版本的环境依赖项,如下所示:

just install a current version of the ambient dependencies like so:

typings i -SA github:DefinitelyTyped/DefinitelyTyped/lodash/lodash.d.ts#672afd8f7b09d839b61eeb4867753876cf79c8b6

这篇关于绝对类型的Lodash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆