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

前端 未结 2 1905
别跟我提以往
别跟我提以往 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:01

    I too am annoyed that you can't alias things the way you might expect. What I've done is ended up using abbreviated 'namespaces' to keep things short.

    import RSV = module("views/researchSectionView")
    var r = new RSV.ResearchSectionView();
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题