My current setup is as follows:
export const PRISMA_TYPES_TO_TS = {
'Int': 'number',
'BigInt': 'number',
'Decimal': 'number',
'Float': 'number',
'String': 'string',
'Bytes': 'string',
'Boolean': 'boolean',
'DateTime': 'Date',
};
const randomKey: string = "randomKey"; // value can vary
if (PRISMA_TYPES_TO_TS.hasOwnProperty(randomKey)) {
// encountering a TS error here stating "No index signature with a parameter of type 'string' was found on type"
console.log('type is valid', PRISMA_TYPES_TO_TS[randomKey]);
} else {
console.log('value is not valid');
}
The issue arises from TypeScript's inability to narrow types after the verification using
PRISMA_TYPES_TO_TS.hasOwnProperty(randomKey)
What are some alternative methods for narrowing types in such scenarios?