首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我怎样才能在VSCode中获得房客类型信息?

我怎样才能在VSCode中获得房客类型信息?
EN

Stack Overflow用户
提问于 2019-05-22 00:33:12
回答 1查看 3.3K关注 0票数 2

使用以下VSCode文件,我在.ts中得到了一个错误:

src\lib\hi.ts

代码语言:javascript
复制
import * as _ from 'lodash';

function testLodash(): void {

  function square(n: number) {
    return n * n;
  }

  return _.map([4, 8], square);
}

误差

代码语言:javascript
复制
Property 'map' does not exist on type 'typeof import("lodash")'.ts(2339)

对于任何常见的提交函数,我都会得到同样的错误。Intellisense只在通过Lodash调用时给出_.类。我猜VSCode找不到我的类型定义,但我不明白为什么。

如果我将导入更改为:

代码语言:javascript
复制
import 'lodash';

我得到了预期的函数,错误消失了,但是我得到了一个新的错误:

代码语言:javascript
复制
'_' refers to a UMD global, but the current file is a module. Consider adding an import instead.ts(2686)

应用建议的QuickFix将以下内容添加到导入中:

代码语言:javascript
复制
import _ from 'lodash';

但我得到了原来的错误。

那么,我需要改变什么才能让这件事奏效呢?

以下是详细信息:

package.json

代码语言:javascript
复制
{
  ...
  "dependencies": {
    ...
    "lodash": "^4.17.11",
    ...
  },
  "devDependencies": {
    ...
    "@types/lodash": "^4.14.130",
    ...
    "typescript": "^3.4.5"
  }
}

tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
     "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "allowJs": true,                       /* Allow javascript files to be compiled. */
    "outDir": "./dist/",                        /* Redirect output structure to the directory. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  }
}

VSCode设置

没有非默认的TS设置

TS版本

3.4.5版

VSCode版本

代码语言:javascript
复制
Version: 1.34.0 (user setup)
Commit: a622c65b2c713c890fcf4fbf07cf34049d5fe758
Date: 2019-05-15T21:59:37.030Z
Electron: 3.1.8
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17134

安装扩展

代码语言:javascript
复制
alanz.vscode-hie-server
alefragnani.Bookmarks
andyyaldoo.vscode-json
christian-kohler.path-intellisense
daiyy.quick-html-previewer
eamodio.gitlens
Edka.haskutil
esbenp.prettier-vscode
fabiospampinato.vscode-todo-plus
flowtype.flow-for-vscode
gcazaciuc.vscode-flow-ide
hoovercj.haskell-linter
jcanero.hoogle-vscode
justusadam.language-haskell
karigari.chat
mrmlnc.vscode-duplicate
ms-vscode.vscode-typescript-tslint-plugin
ms-vsliveshare.vsliveshare
ms-vsliveshare.vsliveshare-audio
ms-vsliveshare.vsliveshare-pack
phoityne.phoityne-vscode
SirTobi.code-clip-ring
WakaTime.vscode-wakatime
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-22 04:35:11

我也有同样的问题,我用这种方式解决了这个问题:

const _ = require('lodash');

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56247879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档