javascript - TypeScript using type parameter -


How can I use type parameter T in the next code block (typeOf, instanceOf, ...). T 'group' is it possible because javascript is not type in thaaks

Export Class Local Storage & lt; T & gt; IOcal Stages & lt; T & gt; Applies {Constructor () {} getKey (): string {if (T is 'Group') return group ""; In Generic, you can not do this for TypeArguments (as you've already felt). But you can check runtime if you use typecript classes:

  class group {} function getKey (item: any): string {if (item item of group) "group "Returns; Other refunds 'invalid'; } Console.log (getKey (new group ()));  

There is no typecript magic in the code above. We are simply using the JavaScript example operator:


Comments