Dyn*_*lon 5 generics alias typescript
TypeScript 1.4 引入了类型别名.这些示例显示了如何使用别名,type MyGreeter = Greeter<string>但是是否可以使用通用别名?
以下示例不起作用:
type GenericAlias<T> = OriginalType<T>
type GenericAlias = OriginalType<T>
Run Code Online (Sandbox Code Playgroud)
是否可以在不进行类型转换的情况下对泛型类别进行别名?
As of TypeScript 1.6 this is now possible.
// from #1616:
type Lazy<T> = T | (() => T);
var s: Lazy<string>;
s = "eager";
s = () => "lazy";
Run Code Online (Sandbox Code Playgroud)
Pre-1.6 answer
No, not yet. You can see developments on this in issue #1616.
As for when this feature will be available...
Lately we've been quite busy with ES6 alignment and the recently announced Angular 2.0 related features. We will get to (re)evaluating some of these type system specific issues but there's no concrete date for issues like this at the moment. - Source
| 归档时间: |
|
| 查看次数: |
1171 次 |
| 最近记录: |