I am having custom types defined like this
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[];
};
When used in a function i get the following error , Type 'string' is not assignable to type 'mimeType'. While destructuring i am giving the type as [mimeType, Extensions[]] but still it is throwing the above error. Can someone help me?
Here is my usage when destructuring it
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;
};