2

Many languages have type aliases, that is, a way to define a short name for a complex (maybe templated) type. For instance in C++ I have this:

using SymbolMap = std::map<SymbolKind, std::map<string, Context*>>;

Now in TypeScript I have fields with this type as well:

class SymbolTable {
    ...

    private _localSymbols: Map<SymbolKind, Map<string, Context>> = new Map<SymbolKind, Map<string, Context>>();
    static private _globalSymbols:  Map<SymbolKind, Map<string, Context>> = new Map<SymbolKind, Map<string, Context>>();
}

which is, mildly said, ugly. Is there a way to make this a bit more reader friendly?

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181

1 Answers1

5

The type alias feature exist in typescript as well, and you can use it like so:

type MyMap = Map<SymbolKind, Map<string, Context>>;

class SymbolTable {
    private _localSymbols: MyMap = new Map();
    private static _globalSymbols: MyMap = new Map();
}

(code in playground)

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299