我有这个接口,想知道是否有可能指定键值能够是潜在的名称。但是,我仍然收到引用错误,说 "bottom" 不属于 IStyles
。我对使用typescript还很陌生,在stackoverflow上搜索时,我没有立刻找到与我所需内容相关的其他答案,如果已经有解决方法而我没有注意到,我很抱歉。
我想要在我的Svelte项目中实现类似于这样的功能,因为这些键名显然是css名称,所以我必须使用真正的名称。
interface IStyles
{
position?: string;
[top | bottom] ?: string | number;
margin?: string | number;
padding?: string | number;
background?: string | Colors;
}
top
或bottom
键中的一个进行关联,而不是两个都连接吗? - tymzap