[英]Use @types definitions in project .d.ts definition file
I'm trying to write a .d.ts file for my project to define some global interfaces. 我正在尝试为我的项目编写一个.d.ts文件,以定义一些全局接口。 However I have a problem using non-global library types inside that definition file. 但是我在该定义文件中使用非全局库类型时遇到问题。 Especially RxJs which I'm trying to reference does not work for me. 特别是我要参考的RxJ对我不起作用。
The thing I thought would work the best was using a triple-slash reference tag to import the types for RxJs, however this didn't work. 我认为最有效的方法是使用三斜杠引用标记导入RxJ的类型,但这没有用。
/// <reference types="rxjs" />
interface IUserService {
user$: rxjs.Observable<IUser>;
}
I found the solution to what I wanted to do: 我找到了想做的解决方案:
import RxJs from 'rxjs';
declare global {
interface IUserService {
user$: RxJs.Observable<IUser>;
}
}
Using declare global { }
I was able to get back into the global namespace. 使用declare global { }
我可以回到全局名称空间。 Typescript is really lacking documentation on this useful directive which is only documented slightly at the end of this page: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#global-augmentation . Typescript确实缺少有关此有用指令的文档,该文档仅在此页末尾进行了少量记录: https : //www.typescriptlang.org/docs/handbook/declaration-merging.html#global-augmentation 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.