Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Typescript Record without manually typing keys

$
0
0

I need some help with Typescript Records.

I'm looking for a solution that avoids manually typing keys names as a key type for a Record, but still keeping intelisense for that object.

Intelisense example

For example:

import { StyleProp, TextStyle } from 'react-native';//I would like to avoid manually typing dozens of keys here. //Can it somehow automatically fetch keys that are already inside 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 know that I can simply use

Record<string, StyleProp<TextStyle>>

But then I lose intelisense for fonts.properties

Without intelisense

If a Record is not made for this, is there anything else that can do this?

Thank you~


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>