您如何引用lib.d.ts类型 [英] How do you refer to lib.d.ts types

查看:1444
本文介绍了您如何引用lib.d.ts类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Typescript中引用lib.d.ts类型?我正在制作一个使用File.lib.d.ts文件类型的类File.

Is there a way to refer to lib.d.ts types in Typescript? I'm making a class called File that uses the lib.d.ts File type.

File.ts

module SomeModule {
   export class File{
      ...
      public foo(file:lib.ts.File) {
          // do stuff
      }
      ...
      public bar(file:SomeModule.File){
          // do some more stuff
      }
   }
}

一年多以前,在 codeplex 上提出了类似的问题,但我找不到此后是否有任何更改,或者是否存在解决方法(不涉及重命名SomeModule.File).

A similar question was asked over a year ago on codeplex but I couldn't find out if anything has changed since then or if a workaround (that doesn't involve renaming SomeModule.File) existed.

推荐答案

有一些解决方法.您可以使用声明的(不生成JS!)全局变量来捕获类型信息并在本地使用它:

There are workarounds. You can use declared (no JS generated!) global variable to capture the type information and use it locally :

declare var FileTypeCapture:File;

module SomeModule {
   export class File{
      public foo(file:typeof FileTypeCapture) {
          // do stuff

      }
      public bar(file:SomeModule.File){
          // do some more stuff
      }
   }
}

这篇关于您如何引用lib.d.ts类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆