Tengo el siguiente objeto ACTIONS
const ACTIONS = { FETCH_ERROR: 'API fetch error', ACTIVATE_QUIZ: 'activate quiz', ACTIVATE_RESULTS: 'activate results', CHECK_ANSWER: 'check current answer', NEXT_QUESTION: 'go to next question', DEACTIVATE_QUIZ: 'deactivate quiz', UPDATE_DATA: 'update all the data', RESET_STATE: 'reset all the state' }
Y quiero especificar que solo se pueden permitir propiedades de tipo cadena. No tengo idea de cómo hacer esto, esa es la razón por la que no estoy proponiendo un intento.
const ACTIONS: { [key: string]: string } = { FETCH_ERROR: 'API fetch error', ACTIVATE_QUIZ: 'activate quiz', ACTIVATE_RESULTS: 'activate results', CHECK_ANSWER: 'check current answer', NEXT_QUESTION: 'go to next question', DEACTIVATE_QUIZ: 'deactivate quiz', UPDATE_DATA: 'update all the data', RESET_STATE: 'reset all the state' }
o use el tipo de utilidad Record<keys, type>
:
const ACTIONS: Record<string, string> = { FETCH_ERROR: 'API fetch error', ACTIVATE_QUIZ: 'activate quiz', ACTIVATE_RESULTS: 'activate results', CHECK_ANSWER: 'check current answer', NEXT_QUESTION: 'go to next question', DEACTIVATE_QUIZ: 'deactivate quiz', UPDATE_DATA: 'update all the data', RESET_STATE: 'reset all the state' }