我想使用 keyof 来基于对象中的可选字段来描述函数的参数。我想添加一个默认值。
interface foo {
bar?: {
opt1: string,
opt2: string
}
}
function func(option: keyof foo["bar"] = "opt1") ...
Run Code Online (Sandbox Code Playgroud)
但作为bar可选我得到Type 'string' is not assignable to type 'never'