繁体   English   中英

将Lodash与TypeScript和JSPM结合使用

[英]Using lodash with typescript and jspm

我可能做错了事,但找不到任何帮助,将不胜感激。 我正在使用打字稿2 + jspm。 我想我使用typeRoots类型 (在版本名称中添加版本号)尝试了tsconfig内部的所有可能性。 我当前的配置如下,它不起作用,而我认为应该...

package.json

  "jspm": {
    "dependencies": {
      "lodash": "npm:lodash@^4.17.4"
    },
    "devDependencies": {
      "@types/lodash": "npm:@types/lodash@^4.14.45",
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4",
      "systemjs": "npm:systemjs@^0.19.41"
    }
  }

tsconfig.json

"typeRoots": [
  "jspm_packages/npm/@types"
]

然后编译器不明白

import * as _ from "lodash"

我懂了

Cannot find module 'lodash'.

根据打字稿文档https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html的建议

现在,如果我删除导入,有趣的是,如果我编写以下代码行,则vcode能够找到合并方法定义(F12)

_.merge(a, b);

但是编译器仍然抱怨

Identifier '_' must be imported from a module

任何想法 ? :)

这不是真正的解决方案,但现在要避免Typescript编译器抱怨这是我要做的

declare const _: any;

我想完成方法签名时就删除该行

请注意,当我导入lodash

 System.import('lodash').then((lodash) => {
     window._ = lodash;
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM