Declaring a single type - “using” equivalent for single type

前端 未结 2 1928
别跟我提以往
别跟我提以往 2021-01-12 00:36

In C# I can do this:

using IAnyType = App.Namespace.Types.IAnyType ;
class BaseClass : IAnyType { }

Is there a Typescript equivalent?

2条回答
  •  天命终不由人
    2021-01-12 01:12

    I actually prefer your original solution over the alternatives:

    import Interfaces = App.Widgets.Interfaces;
    class BaseDialog implements Interfaces.IDialogOptions { }
    

    Without having the alias (Interfaces) you could get naming collisions - which if you have ever had to handle with using statements is a real pain as you end up using an alias or using the full namespace.

    using myAlias = App.Namespace.Types;
    

    At least having an alias for all modules you import means this won't be an issue.

提交回复
热议问题