在 TypeScript 中访问类型提示的全局范围
Access global scope for type hinting in TypeScript
我在 Typescript 中遇到类型提示问题,无法指定全局类型。
举下面的例子
// Builder.ts
module Builder {
class Block {
// ...
function uploadFile(file:File) { /* ... */ }
}
}
//Blocks.ts
module Builder {
module Types {
class Image {
// ...
function uploadFile(file:File) { /* ... */ }
}
class File {
// ...
}
}
}
我在编译时遇到这个错误:
error TS2415: Class 'Image' incorrectly extends base class 'Block'.
Types of property 'uploadFile' are incompatible.
Type '(file: File) => void' is not assignable to type '(file: File) => void'.
这充其量只是误导。
所以在 PHP 中,您可以将 File 指定为 \File 以获取全局文件,但是我无法 find/figure 了解如何在 TypeScript 中执行此操作。
逻辑上(至少对我而言)是 window.File
。
however I cant find/figure out how to do this in TypeScript.
这是一个开放的功能请求:https://github.com/Microsoft/TypeScript/issues/983 您可以在其中表达您的愿望。
请注意,目前有一个解决方法:https://github.com/Microsoft/TypeScript/issues/983#issuecomment-66704566
一个专门针对您的情况:
我在 Typescript 中遇到类型提示问题,无法指定全局类型。
举下面的例子
// Builder.ts
module Builder {
class Block {
// ...
function uploadFile(file:File) { /* ... */ }
}
}
//Blocks.ts
module Builder {
module Types {
class Image {
// ...
function uploadFile(file:File) { /* ... */ }
}
class File {
// ...
}
}
}
我在编译时遇到这个错误:
error TS2415: Class 'Image' incorrectly extends base class 'Block'.
Types of property 'uploadFile' are incompatible. Type '(file: File) => void' is not assignable to type '(file: File) => void'.
这充其量只是误导。
所以在 PHP 中,您可以将 File 指定为 \File 以获取全局文件,但是我无法 find/figure 了解如何在 TypeScript 中执行此操作。
逻辑上(至少对我而言)是 window.File
。
however I cant find/figure out how to do this in TypeScript.
这是一个开放的功能请求:https://github.com/Microsoft/TypeScript/issues/983 您可以在其中表达您的愿望。
请注意,目前有一个解决方法:https://github.com/Microsoft/TypeScript/issues/983#issuecomment-66704566
一个专门针对您的情况: