typescript: Is there a way of saying, “This field is optional, but if it exists, it MUST have a value?”

前端 未结 0 437
谎友^
谎友^ 2020-12-16 09:04
type Fields = {
  [P in "foo" | "bar"]?: number; // in the real code, this is [P in anArrayOfStrings]
};

const field: Fields = {
  "foo&quo         


        
相关标签:
回答
  • 消灭零回复
提交回复
热议问题