News for hackers. Stuff that matters.
Re:Yarn's Future – v2 and beyond by mrspeaker on Thursday January 24, 2019 @11:04AM (#18989811)
Does anyone know of any "third choice" around typing JavaScript? I would love to add types to my code, but I want to write "real" JavaScript: so the code I input is the code that is executed by the browser. I just want the compile step to strip away the type annotations.

There was initially talk of Flow using comments to actually work without touching the source code at all, but I don't think anything came of that... is there anything else on the horizon?

[Edit: Nevermind: I went looking for the github issue about adding types as comments, and it turns out it's already supported by flow: https://flow.org/en/docs/types/comments/ - is there anything like this for TypeScript?]

Re:Yarn's Future – v2 and beyond by Vinnl on Thursday January 24, 2019 @11:10AM (#18989898)
Yes, TypeScript can do type checking on regular Javascript (annotated with comments) as well: https://www.typescriptlang.org/docs/handbook/type-checking-j...
Re:Yarn's Future – v2 and beyond by scrollaway on Thursday January 24, 2019 @11:38AM (#18990212)
> I would love to add types to my code, but I want to write "real" JavaScript: so the code I input is the code that is executed by the browser. I just want the compile step to strip away the type annotations.

That's what Typescript is. Type annotations don't change your code, they're stripped away by babel at compile time. In fact, by default, tsc does compile TS code which fails typechecking, into valid JS code (which will likely error when you use it at least in some circumstances, but can run just fine).

Typescript is a clear superset of JS, so there's no actual logical changes or even syntactical changes done by the compiler. However, you may be confused by the often-used "compilation target" features of babel (and tsc), which is that you may write ES2018 code, target ES5, and have your ES2018 syntactical sugar be turned into ES5-compatible code. This is entirely opt-in, and not related to typescript (other than the fact that Typescript is always compatible with the latest ES spec, so you can use any legal ES2018 syntax in it).

Hope that clears it up…

Re:Yarn's Future – v2 and beyond by dntrkv on Thursday January 24, 2019 @12:16PM (#18990618)
This is where I see a big difference between Flow / TS.

With Flow, the type annotations are just stripped away, none of your Flow code affects runtime code.

This is not so with TS since you have things like Enums, which will be compiled into objects and are part of your runtime code.

Re:Yarn's Future – v2 and beyond by RyanCavanaugh on Thursday January 24, 2019 @12:51PM (#18991014)
If you write type annotations in TS, they're stripped away.

If you write type annotations in Flow, they're stripped away.

There's no difference. TS has some additional features which are purely optional that don't get purely stripped out, but you're not mandated to use them.

Re:Yarn's Future – v2 and beyond by dntrkv on Thursday January 24, 2019 @04:13PM (#18993015)
There is no difference if you limit the use of the tool to not use these features.

In my eyes, it's a philosophical difference between the two, Flow can be more easily integrated into an existing codebase by just adding //@flow at the top the file and has no features which can affect runtime code. Whereas TypeScript tries to be a different language altogether that uses a new file extension, adds new features, and has its own compiler.

When you can implement a tool like this using TS, let me know https://github.com/flowtype/flow-remove-types

Re:Yarn's Future – v2 and beyond by scrollaway on Thursday January 24, 2019 @04:34PM (#18993225)
Typescript doesn't try to be a different language. It tries to be an exact superset of JS: JS with annotations. And you can absolutely implement what you linked, it exists and it's called tsc: the "compiler" you're somehow upset Typescript has (this + checking types is all it does!). Babel does it natively.

Enums are a fair point, those aren't in the ES specs (though I suspect at some point they will be). However, they're an incredible addition and they really are just syntactic sugar for a more complex type of object.

BTW, typescript supports jsdoc-style annotations, and --allowjs even lets it typecheck javascript code. It also supports more, because nobody actually only wants those things; they're not that great on their own.

Re:Yarn's Future – v2 and beyond by dntrkv on Thursday January 24, 2019 @04:44PM (#18993310)
Not sure where you got the idea that I'm upset that TS has a compiler, I'm just pointing out my perspective on the differences between the two tools. I use both on a daily basis.

You might not think the differences is a big deal, but affecting runtime code is a pretty major line to cross. Not that there is anything inherently wrong with that, but at that point it becomes a different tool, in my opinion.

Re:Yarn's Future – v2 and beyond by scrollaway on Thursday January 24, 2019 @06:04PM (#18993962)
No I get you, being able to map the exact code is important. But I think what's happening is you're confused about the ES20XX translation layers. Those aren't at the typescript level, they're at the Babel level … it just so happens that tsc supports that bit, but it's my understanding that this will be going away at some point (eg. typescript will move to only doing the typechecking, and leaving babel to only do the compiling).

enums are a tiny, extremely useful and extremely optional part of the language and they don't warrant this label of "philosophical difference", IMO.

Re:Yarn's Future – v2 and beyond by esamatti on Thursday January 24, 2019 @04:37PM (#18993246)
I think Babel does excatly that if only enable the typescript-preset.
Re:Yarn's Future – v2 and beyond by MehdiHK on Thursday January 24, 2019 @01:10PM (#18991225)
Is there any compiler option or linter config that prevents the use of these extra features?
Re:Yarn's Future – v2 and beyond by RyanCavanaugh on Thursday January 24, 2019 @01:33PM (#18991465)
tslint has no-namespace and no-enum to disallow the two things that create new runtime code
Re:Yarn's Future – v2 and beyond by _hardwaregeek on Thursday January 24, 2019 @11:09AM (#18989881)
Re:Yarn's Future – v2 and beyond by sephoric on Thursday January 24, 2019 @11:11AM (#18989907)
Can confirm, have sometimes added /* * @type Foo */ above a type and VS Code assumed that type was Foo everywhere else in my project, as if I typed `foo: Foo` directly. Didn't even have TypeScript in the project itself, purely an IDE feature. Extremely well thought out and useful ecosystem.
Re:Yarn's Future – v2 and beyond by lmm on Thursday January 24, 2019 @11:18AM (#18989989)
If you're using Babel for compatibility with particular browsers then that can already handle TypeScript. What distinction are you drawing between a compile step that "strips away the type annotations" and one that does something else - what else is it that you consider compiling TypeScript to include?

I have to ask what you're trying to achieve here. Moving types into comments just gives people who build without your typechecker the chance to break your code.

Re:Yarn's Future – v2 and beyond by mrspeaker on Thursday January 24, 2019 @11:29AM (#18990115)
The comment stripping is optional (just for saving bytes on download). The goal is moving away from Babel, and any other unnecessary transpiling steps. Now that JavaScript has (a semi-working) module system, I find my projects having fewer and fewer dot files and far fewer dependencies.

If I can have a folder of plain JS that I know will work in a browser 20 years from now without having to resurrect an ancient/abandoned toolchain, then I'll do that!

Re:Yarn's Future – v2 and beyond by lmm on Thursday January 24, 2019 @04:59PM (#18993453)
Are you gonna hardcode all the HTML and CSS as well? I would expect resurrecting a 100% compatible toolchain for a mainstream source format 20 years from now will be easier than resurrecting a 100% compatible browser. Especially if that format is a stricter/less ambiguous one like typescript.
Re:Yarn's Future – v2 and beyond by Jach on Thursday January 24, 2019 @03:00PM (#18992351)
Not exactly what you're asking, but a "third choice" in general to typed ECMAscript has been ActionScript. A quick google found a transpiler project, but it looks to be abandoned: https://github.com/Cleod9/as3js

Still, I once did Flex development (would compile to a SWF file, or with Adobe Air to a native executable). It was a pleasure -- so long as you used the Flex/Flash Builder IDE (which was itself built on top of Eclipse). Trying to develop in vim was harder, though mainly because of the MXML part, but I still liked MXML better than HTML. Later at the same job I did Node and found that pretty enjoyable too, plus I could use vim all the time.

Tooling is always a concern with a language. I think dynamically typed languages are partially successful because they let you get away with so much less tooling. Though not all dynamic languages are equal in the tooling they can trivially support, e.g. Common Lisp with Slime enables all the usual stuff (who calls x, who sets y, who specializes method z...) and you can use Slime from a variety of other tools.