How to determine generic connection types in TypeScript
we can use:
type stringNumber = string | number;
But what about:
type MapSet<T> = Map<T> | Set<T>;
Is this possible somehow?
PS this is necessary to reduce the length of the interface definitions.
UPDATE:
type MapSet<T> = Map<T> | Set<T>;
this definition is correct in typeScript 1.6, and you can use it today, as Ryan wrote below.
+3
user1338054
source
to share
2 answers
Typical aliases with typical type parameters are found in TypeScript 1.6.
You can wait for this version to arrive or install the TypeScript nightly build ( npm install typescript@next
)
+3
Ryan Cavanaugh
source
to share
This is an interesting question. The following did the compilation, but having to wrap each value is definitely not optimal.
interface MapSet<T> {
wrapper: Map<T> | Set<T>;
}
0
Hath995
source
to share