Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Enhanced enum support #31

Closed
MichalLytek opened this issue Sep 6, 2017 · 2 comments · Fixed by #32
Closed

Enhanced enum support #31

MichalLytek opened this issue Sep 6, 2017 · 2 comments · Fixed by #32

Comments

@MichalLytek
Copy link
Contributor

Right now, you support string array as an enum:

// Enum-like type and definition example.
type Gender = 'male' | 'female';
const Genders = {
  MALE: 'male' as Gender,
  FEMALE: 'female' as Gender,
};

@prop({ enum: Object.values(Genders) })
gender?: Gender;

However we have string enum support in TS now. It would be nice if the decorator function accept also the object type as the enum value and get the string values using Object.values(object) inside:

// true enum type
enum Gender {
  MALE = 'male',
  FEMALE = 'female',
};

@prop({ enum: Gender })
gender?: Gender;

So the signature of the BasePropOptions would be enum?: string[]|object; and you can in runtime check if Array.isArray(enum) to behave like now or convert enum object to values.

@MichalLytek
Copy link
Contributor Author

I can make a PR if you want 😉

@szokodiakos
Copy link
Owner

Hello! Yes, when I saw the new string enums I wanted to make this but currently don't have enough time for it. A PR would be awesome indeed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants