Proposal static type constraints features

Jordan Harband ljharb at gmail.com
Mon Jun 4 05:44:52 UTC 2018


So now for every type annotation, someone has to add `&& undefined`? That
seems like a lot of confusing boilerplate to have to add.

On Sun, Jun 3, 2018 at 10:39 PM, YU HengChun <achun.shx at qq.com> wrote:

> This is easy to solve, we change the word. But the code will be longer.
>
> The original:
>
> ```js
> function f(x) {
>   return typeof x !== 'string' || typeof x === 'undefined';
> }
> ```
>
> The proposal: typeof version
>
> ```js
> function f(x = typeof(String) && undefined ) { // Attention can not be
> omitted: && undefined
>   void typeof(Boolean); // or only: typeof(Boolean);
>   return typeof x !== 'string' || typeof x === 'undefined';
> }
> ```
>
> 这很容易解决, 换个单词就行. 但是代码会更长.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180603/ba32e18b/attachment.html>


More information about the es-discuss mailing list