I am writing my own custom form validators for angular with the following template.
static customFunction(param: number, param2: string): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } => {
return { customError: {param, param2} };
};
}
Instead of key:string
I want to only allow a range of items from a defined enum.
export enum FormErrorEnum {
unknown = 'unknown',
customError = 'customError',
}
export type FormError = keyof typeof FormErrorEnum;
If I try to use either [key: FormError]: any
or [key in FormError]:any
I will get one of two errors.
[key: FormError]: any
results in a TS1337.
[key in FormError]:any
results in the return (customError: {param,param2}
being refused as it does not include all entires in the enum.
I have already looked in this thread. TS version is 3.8 - upgrading is an option.