为什么解构赋值不知道空值是假的并使用默认值?

Why destructuring assignment doesn't know null value as falsy and use default value?

假设我们有一个函数在参数的内部对象中使用一些键:

const api = ({ data: { name } = {} }) =>
  `My name is ${name}.`;

如果我们将 {}{ data: '' }{ data: 0 }{ data: NaN }{ data: undefined } 传递给函数,我们将看到:

'My name is undefined.'

并且不会看到任何错误,因为解构赋值看到 data 是假的并使用 = {} 而不是 name 将是 undefined.

问题: 为什么当我们将null传递给数据键时解构赋值return出错?

api({ data: null });

// ==> Uncaught TypeError: Cannot destructure property 'name' of '{}' as it is null.

根据MDN docs关于对象解构中的默认值:

A variable can be assigned a default, in the case that the value pulled from the object is undefined.