Can someone assist me with Typescript Records?
I'm seeking a solution that eliminates the need for manually typing key names as a key type for a Record, while still maintaining intellisense for that object.
For instance:
import { StyleProp, TextStyle } from 'react-native';
//I want to avoid typing out numerous keys manually here.
//Is there a way to automatically retrieve keys already present within the fonts object?
type TFontKeys =
| 'title'
| 'subtitle'
| 'header'
///////
const fonts: Record<TFontKeys, StyleProp<TextStyle>> = {
title: {
fontSize: 22,
fontWeight: '600',
},
subtitle: {
fontSize: 16,
fontWeight: '600',
},
header: {
fontSize: 16,
fontWeight: '500',
marginBottom: 8,
}}
I am aware I could simply use
Record<string, StyleProp<TextStyle>>
However, this would result in the loss of intellisense for fonts.properties
If a Record does not serve this purpose, is there an alternative solution available?
Many thanks~