<div dir="ltr"><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><br></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```js<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">let a: number = 10<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">a += ‘1’ // Error, cannot convert type string to type number.```</span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">What if  </p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">```"101"```</p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial">is the expected result?</p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><br></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">Would  </span></p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Strict_mode_for_scripts">Strict mode for scripts</a><div><br></div><div>> To invoke strict mode for an entire script, put the exact statement ```"use strict";``` (or ```'use strict';```) before any other statements.<p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```"use static typing"```</span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">suffice?</span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial"><br><br></p></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 25, 2019 at 5:13 PM ViliusCreator <<a href="mailto:viliuskubilius416@gmail.com">viliuskubilius416@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-AU"><div class="gmail-m_1439268435014527978WordSection1"><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span lang="EN-US">> </span><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">Hello, to play the devils advocate: why does JavaScript need static typing? Your proposal doesn't really answer that. Sure, it mentions tooling and IDEs that can provide you with type hints and complain on mistakes<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">I actually did. It keeps unwanted type mutations and bad values away. For example,<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">This:<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```js<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">let a = 10<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">a += ‘1’ // ‘101’<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">// or<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">a += undefined // NaN<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">VS this:<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```js<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">let a: number = 10<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">a += ‘1’ // Error, cannot convert type string to type number.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">// or<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">a += undefined // Error, number doesn’t have nullable mark.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">```<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">This can help developer itself, in runtime, not only at development time. “But IDE wouldn’t allow that.” But what if property in required json(node js), is undefined? Some IDEs don’t have JSON intellisense, so this is where it can get annoying.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">> </span><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">but things like Flow and Typescript do this today already. <u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Yes, but they are compile-time only. Meaning, that in runtime, type mutation and unwanted values can happen.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">> What's your goal, to have JS engines run Typescript(-like) code natively without transpiling?<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">First of, this is compiling. TypeScript is higher level than JS, so it’s compiling. Second, TypeScript code is completely compile-time only. Classes(And other ES8+ code), imports, exports and probably namespaces are the only things which are at runtime also.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">> What's the point of building this feature into engines? It just provides additional complexity.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">I said reasons above. Also as I said, they are optional. Meaning, ne</span><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">w comers can still learn old js code without static types. Besides, doesn’t async, await, classes and other new stuff add complexity to new people to JS?<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51)">> </span><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Where (when) do you expect types to be checked? Should the engine throw early errors (during parsing)?<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Languages normally check types during compile-time. I expect JS to throw</span> errors in runtime, meaning that if you make code <span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">which would throw type error and it’s untouched, then it doesn’t throw an error.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">> What does "static typing" even mean to you in a dynamic scripting language?<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Same thing as in real statically typed languages. Type checking.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">> and what happens when you introduce new types with `eval` or by loading another script?<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Since as I said, they are runtime only type checking.<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white"><u></u> <u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">> However I would be curious to know if anybody has a usage for them at run time<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">They have. `eval` can make type mutation(and if it checks the string, you can still overcome them(inputs or array joining)).<u></u><u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white"><u></u> <u></u></span></p><p style="margin-right:0cm;margin-bottom:16.8pt;margin-left:0cm;background:white"><span style="font-size:12pt;font-family:Georgia,serif;color:rgb(51,51,51);background:white">Also, if transpiling and compiling is better, why not leave JS dead? I mean, compilers can do job instead of JS. It’s just basically useless, compilers can do awesome stuff, so “no need for new features in JS”(and then if we did, wasm would take over in web development, or browsers would overcome ES and use something else instead). </span></p></div><div id="gmail-m_1439268435014527978DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top:1px solid rgb(211,212,222)">
        <tbody><tr>
        <td style="width:55px;padding-top:13px"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td>
                <td style="width:470px;padding-top:12px;color:rgb(65,66,78);font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" style="color:rgb(68,83,234)" target="_blank">www.avast.com</a>
                </td>
        </tr>
</tbody></table><a href="#m_1439268435014527978_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></div>_______________________________________________<br>
es-discuss mailing list<br>
<a href="mailto:es-discuss@mozilla.org" target="_blank">es-discuss@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/es-discuss" rel="noreferrer" target="_blank">https://mail.mozilla.org/listinfo/es-discuss</a><br>
</blockquote></div>