Reputation: 25840
While converting an enumerator from JavaScript into TypeScript, I had to add my own enum - myEnumType
.
If I use such enum as a property type:
prop:myEnumType
it will be expected that the value must be of type myEnumType
.
How can we declare a property in TypeScript that represents the enum itself as a type, as opposed to a value of that type?
I'm trying to expose the enum as a type, via an interface property.
Upvotes: 4
Views: 15244
Reputation: 1509
In myEnumType.ts class
export enum MyEnumType {
Member1,
Member2
}
In Foo.ts class
import { MyEnumType } from './myEnumType';
export interface Foo {
prop: MyEnumType;
}
Upvotes: 2
Reputation: 275849
I'm trying to expose the enum as a type, via an interface property.
You can declare an enum
e.g. in a vendor.d.ts
:
declare enum MyEnumType {
Member1,
Member2,
}
And how would I then declare a property of the enum as a type, via an interface property?
interface Foo {
prop: MyEnumType
}
Upvotes: 4