How to add an enum in class in Typescript
What ever you are trying to do is not possible in TypeScript. As per my understanding, you need a data member of type Status enum. You can update your code this way
enum Status {
Value1,
Value2
};
export class User {
userID: number;
nom: string;
prenom: string;
dateCretation: Date;
status: Status; // can hold either Value1 or Value2 from Status enum
}
You will need to declare the enum
beforehand, and then type it to the properties that you want to have of that type:
export enum Values {
Value1,
Value2
}
export class User {
userID: number;
nom: string;
prenom: string;
dateCretation: Date;
statut: Values
}
Another alternative is that if you know for sure that statut
can only strictly take in two values, of which they are type of, say, string
, then you can do like the following:
export class User {
userID: number;
nom: string;
prenom: string;
dateCretation: Date;
statut: "Value1" | "Value2"
}