在Typescript中导入专用接口

在Typescript中导入专用接口,typescript,phpstorm,webstorm,jetbrains-ide,Typescript,Phpstorm,Webstorm,Jetbrains Ide,这里有一个例子。所有的localfound包导出都是privatelocalfound类的一个实例。相应的类型具有相同名称的接口,但它也没有导出 尽管没有导出localfollow接口,TypeScript和IDE(WebStorm)似乎允许从'@types/localfollow'导入它。但该类型不适用 在customfour.setDriver(…)行之前,此代码没有脱毛问题,也没有导入错误: import * as localForage from 'localforage'; impor

这里有一个例子。所有的
localfound
包导出都是private
localfound
类的一个实例。相应的类型具有相同名称的接口,但它也没有导出

尽管没有导出
localfollow
接口,TypeScript和IDE(WebStorm)似乎允许从'@types/localfollow'导入它。但该类型不适用

customfour.setDriver(…)
行之前,此代码没有脱毛问题,也没有导入错误:

import * as localForage from 'localforage';
import { LocalForage } from '@types/localforage';

var customForage: LocalForage = localForage;
customForage.setDriver('custom');
但结果是错误的:

未解析的函数或方法setDriver()

而这个代码

import * as localForage from 'localforage';

/// <reference path="../../../node_modules/@types/localforage/index.d.ts"/>

var customForage: LocalForage = localForage;
customForage.setDriver('custom');
import*作为“localfound”中的localfound;
/// 
var customfough:localfough=localfough;
setDriver('custom');
成功识别
setDriver
方法

@types
最终到达时,我很高兴,维护
index.d.ts
的相对路径很麻烦


从我所读到的内容和我对@types的日常工作来看,您不需要导入或引用@types,而无需
就可以处理这个案例@类型是按名称自动解析的。因此,对于模块localfollow,将加载@types localfollow。
这里有一个简短的摘要:


我想使用webstorm或phpstrom时的问题可能是,您没有使用内置版本的typescript,而不是您为项目安装的版本。尝试使用自定义typescript版本,并加载已安装在node_模块中的版本。并确保使用TypeScript 2.0

,如果只删除第二次导入和
///无需直接在代码中导入
@type
,则会按名称解析;默认情况下,来自
“node_modules/@types/*”
的文件始终包含在编译范围内,即使tsconfig.json中排除了node_模块。但是,
@types
功能仅在2016.3之后才受支持,因此您需要确保使用最新的WebStormversion@lena谢谢事实上,2016.3没有这个问题,而是自动使用
@type
。我想升级解决了这个问题,这是TS 2.x的正常行为。谢谢,看起来这是真的,以前的IDE版本使用了TS 1.x。