Remove any

This commit is contained in:
Steve Faulkner 2021-01-19 10:05:48 -06:00
parent cd45f2943d
commit c857b9aab9
2 changed files with 10 additions and 14 deletions

View File

@ -1,10 +1,10 @@
import { ChoiceItem, Info, InputType, UiType } from "../Explorer/Controls/SmartUi/SmartUiComponent";
import { addPropertyToMap } from "./SelfServeUtils";
import { addPropertyToMap, CommonInputTypes } from "./SelfServeUtils";
type ValueOf<T> = T[keyof T];
interface Decorator {
name: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
name: keyof CommonInputTypes;
value: ValueOf<CommonInputTypes>;
}
interface InputOptionsBase {
@ -59,9 +59,7 @@ const addToMap = (...decorators: Decorator[]): PropertyDecorator => {
addPropertyToMap(target, propertyName, className, "type", propertyType);
addPropertyToMap(target, propertyName, className, "dataFieldName", propertyName);
decorators.map((decorator: Decorator) =>
addPropertyToMap(target, propertyName, className, decorator.name, decorator.value)
);
decorators.map(decorator => addPropertyToMap(target, propertyName, className, decorator.name, decorator.value));
};
};

View File

@ -79,7 +79,7 @@ export const addPropertyToMap = <T extends keyof CommonInputTypes, K extends Com
target: unknown,
propertyName: string,
className: string,
descriptorName: string,
descriptorName: keyof CommonInputTypes,
descriptorValue: K
): void => {
const context =
@ -92,11 +92,9 @@ export const updateContextWithDecorator = <T extends keyof CommonInputTypes, K e
context: Map<string, CommonInputTypes>,
propertyName: string,
className: string,
descriptorName: string,
descriptorName: keyof CommonInputTypes,
descriptorValue: K
): void => {
const descriptorKey = descriptorName as keyof CommonInputTypes;
if (!(context instanceof Map)) {
console.log(context);
throw new Error(`@SmartUi should be the first decorator for the class '${className}'.`);
@ -104,13 +102,13 @@ export const updateContextWithDecorator = <T extends keyof CommonInputTypes, K e
const propertyObject = context.get(propertyName) ?? { id: propertyName };
if (getValue(descriptorKey, propertyObject) && descriptorKey !== "type" && descriptorKey !== "dataFieldName") {
if (getValue(descriptorName, propertyObject) && descriptorName !== "type" && descriptorName !== "dataFieldName") {
throw new Error(
`Duplicate value passed for '${descriptorKey}' on property '${propertyName}' of class '${className}'`
`Duplicate value passed for '${descriptorName}' on property '${propertyName}' of class '${className}'`
);
}
setValue(descriptorKey, descriptorValue, propertyObject);
setValue(descriptorName, descriptorValue, propertyObject);
context.set(propertyName, propertyObject);
};