Trying to get some data for a modal based on a feature
name.
The feature itself is a string coming from an API.
The messages
object is for translating the strings in other countries.
import { defineMessages } from 'react-intl';
messages = defineMessages({
userLimitsHeading: {
defaultMessage: 'User limits',
},
userLimitsSubheading: {
defaultMessage: 'Get the flexibility to grow your team beyond 10 users.',
},
agentLimitHeading: {
defaultMessage: 'Agent limits',
},
agentLimitSubheading: {
defaultMessage: 'Get the flexibility to grow your team beyond 3 agents.',
},
});
interface ModernizedPlanSelectionModalTypes {
feature: string;
}
const getData = (feature) => {
const heading = messages[`${feature}Heading`];
const subHeading = messages[`${feature}Subheading`];
return {
heading,
subHeading,
};
}
I'm getting 2 typescript errors in the getData function, specifically in the bit where I grab the message with the concatenated string key:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'userLimitsHeading: { id: string; description: string; defaultMessage: string; }; userLimitsSubheading: { id: string; description: string; defaultMessage: string; }; ... //Continues on for the rest of them
No index signature with a parameter of type 'string' was found on type ' userLimitsHeading: { id: string; description: string; defaultMessage: string; }; userLimitsSubheading: { id: string; description: string; defaultMessage: string; }; //Continues on for the rest of them'