Are typical TypeScript aliases possible?

TypeScript 1.4 entered type aliases . The examples show how to use aliases of type type MyGreeter = Greeter<string> , but is it possible to have common aliases?

The following examples do not work :

 type GenericAlias<T> = OriginalType<T> type GenericAlias = OriginalType<T> 

Is it possible to use aliases of general types in general without matching them?

+5
source share
2 answers

According to TypeScript 1.6, this is possible.

 // from #1616: type Lazy<T> = T | (() => T); var s: Lazy<string>; s = "eager"; s = () => "lazy"; 

The answer is up to 1.6.

No, not yet. You can see events on this in issue # 1616 .

How to do it when this feature is available ...

We have been very busy lately with ES6 alignment and the recently announced Angular 2.0 features. We will receive an (re) assessment of some of these problems associated with a particular type of system, but there is no specific date for such issues. - Source

+3
source

According to the release notes , generic type aliases are now available starting with TypeScript 1.6.

0
source

Source: https://habr.com/ru/post/1215356/


All Articles