如果我有这样代码
const AlignContent = {
'content-start': {alignContent: 'flex-start'},
'content-center': {alignContent: 'center'},
'content-end': {alignContent: 'flex-end'},
'content-stretch': {alignContent: 'stretch'},
'content-between': {alignContent: 'space-between'},
'content-around': {alignContent: 'space-around'},
}
const AlignItems = {
'items-stretch': {alignItems: 'stretch'},
'items-start': {alignItems: 'flex-start'},
'items-center': {alignItems: 'center'},
'items-end': {alignItems: 'flex-end'},
'items-baseline': {alignItems: 'baseline'},
}
const styles = {
...AlignContent,
...AlignItems
}
function apply(styles: ??? ) {
//apply code here
}
如何创建要引用keyof typeof styles
接口,所以我想像这样调用apply:
apply('items-stretch content-around')
注意:???不是string
类型,但我希望从keyof typeof styles
中建议每个
1条答案
按热度按时间k97glaaz1#
您可以使用Template Literal Types来实现此目的。
在你的例子中,你可以这样写:
你可以在我做的TSPlayground里看看。