I have my own custom types defined as shown below:
export type Extensions =
| '.gif'
| '.png'
| '.jpeg'
| '.jpg'
| '.svg'
| '.txt'
| '.jpg'
| '.csv'
| '.zip';
export type mimeType = 'image' | 'application' | 'text';
export type FileType = {
[key in mimeType]?: Extensions[];
};
While using these types in a function, I encounter the error message
Type 'string' is not assignable to type 'mimeType'.
Even though I specify the type as [mimeType, Extensions[]]
during destructuring, the error persists. Can someone provide assistance?
Below is how I am utilizing these types during destructuring:
export const getAcceptedFileTypes = (mimeTypes: FileType) => {
const acceptedTypes: Accept = {};
Object.entries(mimeTypes).forEach(([key, extensions]: [mimeType, Extensions[]]) => {
if (key === 'text') {
acceptedTypes['text/*'] = extensions;
} else if (key === 'image') {
extensions.forEach(
(image) => (acceptedTypes[`image/${image.substring(1)}`] = [image])
);
} else {
extensions.forEach(
(application) =>
(acceptedTypes[`application/${application.substring(1)}`] = [
application,
])
);
}
});
return acceptedTypes;
};