Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

re-export Typescript enum from namespace?

I have an enum definition in module 'some-lib'. I want to re-export it from a namespace in my module, something like this:

import { PaymentType } from 'some-lib';

namespace Payout {
    export enum PaymentType = PaymentType;
}

I'm not having any luck. I want to do this in order to alias the enum and put it into a different namespace to avoid collisions with other types with the same name. I don't want to have to define a duplicate copy of the enum in my code, and have to maintain all the enum values.

Is there any way Typescript supports this currently?

like image 345
Patrick Finnigan Avatar asked Dec 07 '17 18:12

Patrick Finnigan


1 Answers

Yes, there's a way to do this, e.g.:

import { PaymentType as _PaymentType } from 'some-lib';


namespace Payout {
  export import PaymentType = _PaymentType;
}

or alternatively:

import * as SomeLibTypes from 'some-lib';


namespace Payout {
  export import PaymentType = SomeLibTypes.PaymentType;
}

reference: https://github.com/Microsoft/TypeScript/issues/20273#issuecomment-347079963

like image 134
Patrick Finnigan Avatar answered Oct 19 '22 09:10

Patrick Finnigan