我知道我们可以使用 Omit<>
在没有特定 Prop 的情况下输入某个对象。
我希望我们也可以将它用于字符串文字:
type possibleStrings = 'A' | 'B' | 'C'
type AorB = Omit<possibleStrings, 'C'>
但是当尝试在函数中为其参数使用类似的东西时,我收到此错误:
Type 'Pick' cannot be used as an index type.
最佳答案
您可以使用 Exclude
来省略字符串文字中的单个字符串。
type possibleStrings = 'A' | 'B' | 'C'
type AorB = Exclude<possibleStrings, 'C'>
关于typescript - 如何在 TypeScript 的字符串文字中省略字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60733363/