Having trouble mapping a string to an enum and receiving the error message
TypeError: Cannot convert undefined value to object
export enum CallErrorType {
UNAUTHENTICATED,
}
const handler: {
[key in CallErrorType]: (message: string) => void;
} = {
[CallErrorType.UNAUTHENTICATED]: message => {
console.log('----> Error UNAUTHENTICATED', message);
},
};
const CallErrorTypeHandler = (errorCode: string, message: string) => {
console.log({errorCode});
const mapped =
CallErrorType[errorCode as keyof typeof CallErrorType];
if (mapped !== undefined) {
return handler[mapped](message);
} else {
console.error('Invalid error string:', errorCode);
}
};
Looking for guidance on my approach.
tsconfig (React Native)
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Native",
"_version": "3.0.2",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"types": ["react-native", "jest"],
"lib": [
"es2019",
"es2020.bigint",
"es2020.date",
"es2020.number",
"es2020.promise",
"es2020.string",
"es2020.symbol.wellknown",
"es2021.promise",
"es2021.string",
"es2021.weakref",
"es2022.array",
"es2022.object",
"es2022.string"
],
"allowJs": true,
"jsx": "react-native",
"noEmit": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": false,
"esModuleInterop": true,
"skipLibCheck": true
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
Encountering another issue now:
TypeError: 0, _$$_REQUIRE(_dependencyMap[3](...)rror").CallErrorTypeHandler is not a function (it is undefined)