【发布时间】:2020-03-21 17:28:48
【问题描述】:
我目前有这种类型
export type Styles = Record<string, Style>
我是这样用的
// Button.styles.ts
const styles: Styles = {
primary: ({ colors }) => ({
backgroundColor: colors.primary,
}),
secondary: ({ colors }) => ({
backgroundColor: colors.secondary,
}),
}
但是当我将它导入另一个文件时,我没有自动完成
import styles from './Button.styles.ts'
// styles.
// I get nothing if I start typing this, but I want to see a list of "primary, secondary"
基本上,我想推断它的键,以便在使用对象时自动完成
【问题讨论】:
标签: typescript key record type-inference