【问题标题】:WebStorm 9 TypeScript intellisense (code completion) failsWebStorm 9 TypeScript 智能感知(代码完成)失败
【发布时间】:2015-01-28 07:08:34
【问题描述】:

我的外部库导入了一些类定义。智能感知仅部分起作用,见下文。

import BB = require('../services/BB');
var r = new BB.Model.Repository();
var name: string = r.name; // Ok, we've got intellisense here

var func = (repo) => { }; // No intellisense here -- ok of course
var func2 = (repo: BB.Model.Repository) => { }; // No intellisense -- why?
var func3 = function(repo: BB.Model.Repository) { }; // No intellisense -- why?
var func4: (r: BB.Model.Repository)=>void = function(repo): void { }; // No intellisense -- why?
var func5 = () => {
  var repo = new BB.Model.Repository();
  var name:string = repo.name; // Ok, we've got intellisense here
};
var func6 = (repo: any) => {
  var name: string = (<BB.Model.Repository>repo).name; // No intellisense here -- why?
};

有什么问题?我的图书馆有什么问题,还是只是 WebStorm?

顺便说一句,库导出是这样跨越几个文件的:

// BB.Model.Repository.ts
export = Repository;
class Repository { name: string; }

// BB.Model.ts
export import Repository = require("./BB.Model.Repository");

// BB.ts
export import Model = require ('./BB.Model');

【问题讨论】:

  • 我建议创建一个支持票,提供详细信息(Model.Repository 的外观,您如何尝试获得智能等)

标签: typescript intellisense webstorm


【解决方案1】:

import BB = require('../services/BB');

只有在有文件 /services/BB.ts 的情况下才能使用默认的 TypeScript 语言服务。我怀疑没有这样的文件,你得到的智能感知只是由Webstorm 完成的一些偶然的+不可靠的很棒的代码分析,就像它对 JavaScript 所做的一样。 JavaScript 的智能感知从不保证可靠。

TypeScript 的类型声明空间中可能没有类型 BB.Model.Repository

【讨论】:

  • 感谢您的留言。但是,路径没问题,如果我重命名 BB.ts,tsc 也会哭,如果删除所有编译的 .js 文件,则没有任何变化。另外,我在 Visual Studio 中有相同的文件和路径,它的智能感知工作正常。这似乎与 WebStorm 有关。
【解决方案2】:

我已经报告了这个问题,JetBrains 出现了一个问题: https://youtrack.jetbrains.com/issue/WEB-14844

更新。他们说它已在版本 10 中修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2020-09-06
    • 2022-01-09
    • 2016-04-03
    • 2021-09-02
    • 2020-04-07
    • 1970-01-01
    相关资源
    最近更新 更多