I have a function called createFields
structured like this:
The map
function being used here is from the lodash library.
const createFields = (usecase: SchemaObject): FieldInterface[] => {
// TODO: Make the form blueprint to be generated from JSON schema
const properties = usecase.properties;
const requiredProperties = usecase.required || [];
if (properties && isSchemaObject(properties)) {
return map(
properties,
(value: SchemaObject, key: string): FieldInterface => {
return {
type: value.type,
name: key,
label: key,
readonly: false,
required: requiredProperties.includes(key),
validations: [],
};
},
);
}
return [];
};
An issue has arisen where TypeScript is flagging an error with the return value of the map
function and the return value of the iteratee function.
This mysterious problem has left me scratching my head. Even though the code clearly returns an object, TypeScript insists that there is a return of type boolean
. In fact, changing the return type to boolean
only results in a different error message altogether.
Could anyone shed some light on what might be causing this confusion? How is it possible for boolean
to be returned at all?