I see one example to use Mapped types for type maps to create a type from object and I would like to use that in my case as following so I can replace the Function
type to fix the eslint error
Don't use 'Function' as a type. The 'Function' type accepts any function-like value. It provides no type safety when calling the function, which can be a common source of bugs.
enum ApiEnum {
CREATE_NAME = 'CREATE_NAME',
CREATE_COMPANY = 'CREATE_COMPANY',
UPDATE_NAME = 'UPDATE_NAME',
}
type CreateName = (variables: number) => Promise<{data: number}>;
type CreateCompany = (variables: string) => Promise<{data: string}>;
type UpdateName = (variables: Record<string, number>) => Promise<{data: Record<string, number>}>;
function createName(variables: number){
return {data: variables}
}
function createCompany(variables: string){
return {data: variables}
}
function updateName(variables: Record<string, number>){
return {data: variables}
}
// error from eslint
// Don't use `Function` as a type. The `Function` type accepts any function-like value.
const api: Map<ApiEnum, Function> = new Map([
[ApiEnum.CREATE_NAME, createName as Function],
[ApiEnum.CREATE_COMPANY, createCompany as Function],
[ApiEnum.UPDATE_NAME, updateName as Function],
]);