> Le 5 sept. 2019 à 23:39, Andrea Giammarchi <[email protected]> a 
> écrit :
> 
> This is basically a solution to a common problem we have these days, where 
> modules published in the wild might have a `default` property, to support ESM 
> logic, or not.
> 
> ```js
> // current optional chaining logic
> const imported = exported?.default ?? exported;
> 
> // my "mice operator" proposal
> const imported = exported<?.default;
> ```
> 


The semantics of the `?.` in `exported?.default` is not to check whether the 
`default` property exists, but whether `exported` evaluates to undefined or 
null. If the `default` property is absent, `exported.default` has always 
evaluated to `undefined`, and there is no need to optional chaining operator. 
So that I guess you actually meant:

``js
const imported = exported.default ?? exported;
```


—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to