Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make a generic? #3

Open
totoblabla3 opened this issue Dec 1, 2021 · 0 comments
Open

How to make a generic? #3

totoblabla3 opened this issue Dec 1, 2021 · 0 comments

Comments

@totoblabla3
Copy link

totoblabla3 commented Dec 1, 2021

@Enum("text")
export class PeriodUnit extends EnumType<PeriodUnit>() {

    static readonly DAY = new PeriodUnit('d');

    private constructor(
        readonly text: string,
    ) {
        super()
    }
}
export function EnumProp<T extends IStaticEnum<T> & { text: string }>(
    enumCls: T,
    options?: PropOptions
) {
    return (target, propertyKey) => {
        Prop({
            ...(options as object),
            type: String,
            set: (v: T) => v.text,
            get: (v: string) => enumCls.valueOf(v)
        })(target, propertyKey);
    }
}
@Schema()
export class Period {

    @Prop({ required: true })
    value: number

    @EnumProp(PeriodUnit,{
        required: true
    })
    unit: PeriodUnit
}

Argument of type 'typeof PeriodUnit' is not assignable to parameter of type 'IStaticEnum<typeof PeriodUnit> & { text: string; }'

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

No branches or pull requests

1 participant