News for hackers. Stuff that matters.
Re:TypeScript at Slack by vmasto on Tuesday April 11, 2017 @04:54PM (#14092340)
Although I don't use TypeScript (I'm looking at Flow more and more recently instead) I have to acknowledge Microsoft's huge contribution to the JS scene (and not only) with TS and VSCode, truly exceptional products.

What's more interesting to me is that everyone who converts their code into Flow or TS immediately finds at least N bugs (albeit small).

It's also quite amusing that this article came out today where HN's top article for a few hours was a bashing against Electron (and Slack specifically).

Re:TypeScript at Slack by Sophistifunk on Tuesday April 11, 2017 @08:56PM (#14093924)
I like and have used them both, but for me there's two points that are massively in favour of TypeScript. The first, is that TS is written in TS, rather than OCaml. The second, is that Microsoft has a long history of developing and more importantly supporting dev tools, and is working on TypeScript for TypeScript's sake. Facebook is (and they're open about this) mainly concerned with Facebook's use-cases, and this drives their OSS products such as React(-native) and Flow.
Re:TypeScript at Slack by KurtMueller on Wednesday April 12, 2017 @01:16AM (#14094966)
> The first, is that TS is written in TS, rather than OCaml

I think being written in OCaml would be a benefit, rather than a negative. One of the reasons I'm interested in ReasonML, which powers Facebook's Flow, is that is based off of Bloomberg's Bucklescript, which is based off of OCaml.

I never knew the power of types (specifically algebraic data types) and the convenience of using them until I discovered them in F# (and Elm).

Re:TypeScript at Slack by Sophistifunk on Wednesday April 12, 2017 @02:18AM (#14095246)
It's not that I'm against OCaml, I've tried to learn it a few times but the toolchain was a PITA. The benefits of self-hosting is that the more you use TypeScript, the more qualified you become to contribute, to troubleshoot, and to if-necessary help shoulder the burden of maintenance should Facebook/Microsoft decide it's no-longer profitable.
Re:TypeScript at Slack by chenglou on Wednesday April 12, 2017 @02:50AM (#14095371)
I work on Reason, mentioned above. The goal of Reason is exactly to expose a polished layer over the OCaml toolchain: http://facebook.github.io/reason/

Give it a try! Ping us if you need to: https://github.com/facebook/reason#community

Re:TypeScript at Slack by mattferderer on Wednesday April 12, 2017 @12:44PM (#14099374)
I really like the idea of Reason & the community is pretty nice from my experience. At the same time, installing it on Windows is a huge pain. Windows 10 was feasible. Windows 7 (because Enterprises can't ever upgrade) is really hard to install it in my experience. I understand this has more to do with OCaml on Windows (which is odd since F# is very similar to OCaml). By the way, I should also mention that F# has Fable which compiles F# to JavaScript. It would be great if the Reason & Fable communities worked together if you're not already.
Re:TypeScript at Slack by Sophistifunk on Wednesday April 12, 2017 @08:47AM (#14097086)
I was under the impression Reason was a library that let you write build files in OCaml? I'm not sure how this helps your average JavaScript programmer make sense of the source to flowtype.

Edit: Never mind, you're referring to my complaint about the OCaml toolchain. Carry on :D

Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @03:15PM (#14100849)
Advancements in Typescript's typing benefit itself.

Plus self-hosting in this case also means that Typescript runs everywhere JS runs, including use cases of compiling Typescript on the fly directly in a browser or very easily including Typescript compilation in NodeJS toolchains or anywhere else JS may run.

Re:TypeScript at Slack by djtriptych on Tuesday April 11, 2017 @06:03PM (#14092927)
And AJAX :)

I'm also really hoping that the current crop of JS programmers learn event-driven / reactive style programming, and for that, RX is probably the best JS library out.

Re:TypeScript at Slack by nathan_f77 on Wednesday April 12, 2017 @02:39AM (#14095335)
Man, there's so many tools and styles to learn and evaluate.

I'm still relatively new to React and React Native, and have enjoyed writing some apps with Redux. It took me a while to understand the need for redux-thunk, and now I'm about to get started with redux-saga [1].

I'm totally unfamiliar with RxJS, but some of the concepts sound familiar. Do I need to learn and use RxJS if I'm already using redux and redux-saga?

I found this SO answer [2], and this post [3], which compares redux-observable and redux-saga.

This guide [4] looks pretty good, too.

[1] https://github.com/redux-saga/redux-saga

[2] http://stackoverflow.com/a/40027778/304706

[3] https://hackmd.io/s/H1xLHUQ8e

[4] https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

EDIT: OK wow, as soon as you get to the "double click" stream diagram (in link [4]), it all starts to make sense. This is pretty amazing.

EDIT 2: The example on http://reactivex.io/ is also good. I didn't realize it was available for so many languages: Java, .Net, JS, Swift. This sounds like something I need to learn.

EDIT 3: This is the best programming guide I have ever read ([4]). It starts with a real problem, then goes on to show how you would solve it in RxJS in a rudimentary and familiar way. Then it expands on and successively simplifies that solution, to show how you would solve it in the idiomatic way. It's really the perfect way to learn these concepts.

> A metastream for responses looks confusing, and doesn't seem to help us at all. We just want a simple stream of responses, where each emitted value is a JSON object, not a 'Promise' of a JSON object. Say hi to Mr. Flatmap: a version of map() that "flattens" a metastream, by emitting on the "trunk" stream everything that will be emitted on "branch" streams. Flatmap is not a "fix" and metastreams are not a bug, these are really the tools for dealing with asynchronous responses in Rx.

Re:TypeScript at Slack by acemarke on Wednesday April 12, 2017 @01:12PM (#14099644)
Hi. I keep a big list of links to high-quality tutorials and articles on React, Redux, and related topics, at https://github.com/markerikson/react-redux-links . Specifically intended to be a great starting point for anyone trying to learn the ecosystem, as well as a solid source of good info on more advanced topics.

In particular, I have a category of articles for "Redux Side Effects" [0], which includes discussion of thunks and sagas, as well as comparisons between various side effect approaches. One particularly good article is "What is the right way to do async operations in Redux?" [1]. I also wrote a blog post responding to various concerns about use of thunks and sagas [2].

[0] https://github.com/markerikson/react-redux-links/blob/master...

[1] https://decembersoft.com/posts/what-is-the-right-way-to-do-a...

[2] http://blog.isquaredsoftware.com/2017/01/idiomatic-redux-tho...

Re:TypeScript at Slack by bpizzi on Wednesday April 12, 2017 @04:07AM (#14095715)
You might also like this: https://github.com/Day8/re-frame

It's not js/es6 (re-frame is a react-based redux-like framework for clojurescript) but the author does a good job at explaining how reactive programming go well with functionnal programming and immutability.

Re:TypeScript at Slack by Stoids on Wednesday April 12, 2017 @11:56AM (#14098915)
That's one of my favorite repos to point colleagues to who feel overwhelmed by modern front-end development. Doesn't get bogged down in tooling or implementation details and explains at a high level the problems all these libraries are trying to solve.

It's a good foundation to crudely explain the pieces. React-Redux connected components are responsible for domino 1, Redux reducers domino 2, effects libraries like sagas/thunks/observables domino 3, selectors/getters for domino 4, React and the VDOM abstracting most of the concerns domino 5 and 6 away from you.

Obviously not perfect, but feels like it helps with choice angst a bit.

Re:TypeScript at Slack by zghst on Tuesday April 11, 2017 @07:01PM (#14093281)
I spent a lot of the earlier parts of my life hating MS, however later after working at a .NET shop and with the late developments at the company, my love for MS is becoming near-infinite. Reactive is definitely the way to go
Re:TypeScript at Slack by mmgutz on Tuesday April 11, 2017 @07:55PM (#14093572)
It's strange but I went the other way. I started hating MS because of working in .NET. Basically, if something wasn't blessed by MS, it wasn't used.

There were open source MVC projects but since MS only blessed ASP.NET forms back then, you couldn't convince managers to use MVC. Same with IoC. Same with ORMs

I do like the new Microsoft. VS.Code is hands down the best all-around editor right now. TypeScript is awesome sauce.

Re:TypeScript at Slack by scalatohaskell on Wednesday April 12, 2017 @02:24AM (#14095271)
> There were open source MVC projects but since MS only blessed ASP.NET forms back then, you couldn't convince managers to use MVC. Same with IoC. Same with ORMs

but that's not really Microsoft's fault

Re:TypeScript at Slack by shouldbworking on Tuesday April 11, 2017 @10:19PM (#14094215)
VSCode and Typescript are stellar. In the case of Typescript, possibly industry-changing long term.

However, the .NET stack still suffers greatly from what you mentioned. The Microsoft world is like the Oracle world, you either use their stuff for everything or never touch it.

I'm confident that .NET core will change this when it's mature enough, but that's still ~2 years away.

Re:TypeScript at Slack by KurtMueller on Wednesday April 12, 2017 @01:19AM (#14094979)
> In the case of Typescript, possibly industry-changing long term.

I feel that way about a related Microsoft product, F#. It's too bad that it doesn't get the same amount of love as Typescript. I think it's more powerful yet just as easy to use in almost every way - I never knew how powerful or expressive algebraic data types could be until I used F#.

Re:TypeScript at Slack by NicoJuicy on Wednesday April 12, 2017 @06:49AM (#14096438)
Too bad nobody gives an example. Check out http://fsharp.github.io/FSharp.Data/ for an example why f# is 'powerful'
Re:TypeScript at Slack by mattferderer on Wednesday April 12, 2017 @12:47PM (#14099414)
Repeating myself a bit in this thread. If you love F#, try checking out Fable &/or Reason. Fable compiles F# to JavaScript and Reason is Facebook's attempt at OCaml to JavaScript. F# !== Ocaml but F# == Ocaml
Re:TypeScript at Slack by daxfohl on Tuesday April 11, 2017 @11:57PM (#14094634)
I've gone, and continue to go, both ways simultaneously. They put a lot of effort into creating awesome experiences to bring developers on board. They also run a business that caters to clients who need "enterprisey" stuff backwards compatible with COBOL.NET or whatever and try to push that along with the good stuff. So it goes. I can't complain too much.
Re:TypeScript at Slack by bobwaycott on Tuesday April 11, 2017 @10:10PM (#14094189)
I started here, too. First production app was an early C# ASP.NET OSHA safety management and training platform for Mohawk carpets, built from the ground up back in 2007-08. Experienced all these headaches. Next major project was Python-based. Never went back to .NET.
Re:TypeScript at Slack by NicoJuicy on Wednesday April 12, 2017 @06:51AM (#14096445)
Asp.net forms was a monster. Asp.net Mvc was not
Re:TypeScript at Slack by bobwaycott on Wednesday April 12, 2017 @01:56PM (#14100047)
The MVC variety was barely getting started when I was working at the time.
Re:TypeScript at Slack by smt88 on Tuesday April 11, 2017 @06:39PM (#14093162)
I like Flow better as a concept, but the tooling for TypeScript is absolutely amazing.
Re:TypeScript at Slack by WhitneyLand on Tuesday April 11, 2017 @07:22PM (#14093398)
Please tell what you like better. I was surprised when even the flow lead at FB said it doesn't really provide any advantage over TS.
Re:TypeScript at Slack by muglug on Tuesday April 11, 2017 @07:51PM (#14093544)
For me, I like how it's designed to complement the language, not to replace it with a (very closely related) cousin.

The conversion from JS-with-flow-types to plain JS is just a matter of stripping out that type information, which I feel is conceptually simpler than TypeScript's approach.

Re:TypeScript at Slack by shouldbworking on Tuesday April 11, 2017 @10:24PM (#14094240)
To me it doesn't matter that typescript replaces js because TS is forwards and backwards compatible, something nobody else is really attempting.

typescript (unlike Babel) is designed to output JavaScript that's as close as possible to what a human would write. If you get tired of Typescript you just transpile your code down to js one last time and forget about it.

Look at the output of Babel vs Typescript and you'll see what I mean about human friendliness. IMO the best tools are the ones easy to get rid of and typescript definitely scratches that itch.

Re:TypeScript at Slack by woah on Wednesday April 12, 2017 @01:53AM (#14095128)
Babel actually started with the express goal of outputting human-readable Javascript. It obviously hasn't stayed that way. IMO, Typescript hasn't stayed that way either. Trying to shoot for a compilation target that is useable as source code is pretty foolish.

The nice thing about Flow is that the compilation step is nothing more than stripping out the typing syntax. It is ACTUALLY easy to get rid of. I will say that the tooling is way better in Typescript.

Re:TypeScript at Slack by dotancohen on Wednesday April 12, 2017 @01:09AM (#14094929)
> the best tools are the ones easy to get rid of

Thank you, you've just summed up the entire proprietary vs FOSS debate _and_ the bus factor in a way that anybody could understand! I am definitely going to be repeating this wisdom!

Re:TypeScript at Slack by johnfn on Wednesday April 12, 2017 @01:47AM (#14095090)
This is a common misconception about Typescript. Typescript has no additional features over (ES6+) JavaScript that are not part of the type system.
Re:TypeScript at Slack by harg on Wednesday April 12, 2017 @04:22AM (#14095786)
Re:TypeScript at Slack by johnfn on Wednesday April 12, 2017 @04:33AM (#14095844)
Alright, I'll give you enums. I don't actually use enums because they have been superseded by string union types, which are generally better. (And are just types)
Re:TypeScript at Slack by fknop on Wednesday April 12, 2017 @05:41AM (#14096126)
Enums are really nothing else than a map string/integer.
Re:TypeScript at Slack by Chyzwar on Wednesday April 12, 2017 @02:46AM (#14095357)
Decorators, interfaces, namespaces, readonly, private and there is probably more corner cases. Typescript compile to JavaScript and it smell like lock-in. In flow you can simply strip type annotations, and you are back to pure JS.
Re:TypeScript at Slack by johnfn on Wednesday April 12, 2017 @04:03AM (#14095693)
Decorators are ES7 stage 1 and can be found in Babel. (They were actually demanded by the angular team.)

Interfaces are types. Namespaces are namespaced types. Readonly and private are type modifiers. You strip out all of those and you have a working JavaScript program.

I don't understand why this myth persists.

Re:TypeScript at Slack by bakkoting on Wednesday April 12, 2017 @06:57PM (#14102525)
Decorators, and class fields, are pre-stage-4 ES proposals. That means they are not part of JavaScript. Moreover, what ends up eventually landing, especially in the case of decorators, is unlikely to work quite the same as what TypeScript implements.

So "Typescript has no additional features over (ES6+) JavaScript that are not part of the type system." is just false.

(Babel has plugins for all kinds of things that aren't part of JavaScript. The team is working on expressing more clearly which plugins are for experimental features and which are settled.)

Re:TypeScript at Slack by johnfn on Wednesday April 12, 2017 @10:04PM (#14103529)
You're moving the goalposts.

GP was concerned about MS nefariously introducing vendor lock-in by implementing a bunch of their own proprietary features. I've demonstrated pretty clearly that

1. It's not MS's implementation - it's an implementation of an ES proposal.

2. For the one example you could find, MS didn't even want to do it - it was requested by Google for Angular and done as essentially a compromise. If you browse the TS repository, you can find issue after issue of the TS team refusing to add features that aren't part of the ES standard.

I think this shows fairly definitively that this is not a case of MS trying to lock you in to their product.

Re:TypeScript at Slack by bakkoting on Thursday April 13, 2017 @04:33AM (#14105181)
I'm not making a case for or against TypeScript; I'm just concerned that people be aware what is and is not part of JavaScript.

You said that TypeScript had no additional features except types. That's all I'm responding to: I'm pointing out this isn't the case. Class fields are, currently, not part of JavaScript. Neither are decorators.

(We're working on it - but actually a concern which has come up is that we might end up with something which breaks TypeScript, because the proposals are still in the early stages and therefore subject to radical changes.)

Re:TypeScript at Slack by msoad on Tuesday April 11, 2017 @07:56PM (#14093580)
Flow is a different language than JS. Keeping the .js extension doesn't make it a "close to JS" language. TypeScript and Flow are both supersets of JS
Re:TypeScript at Slack by smt88 on Tuesday April 11, 2017 @08:02PM (#14093620)
> Flow is a different language than JS

How so? Isn't JS-with-Flow just JS with specially formatted comments?

Re:TypeScript at Slack by abritinthebay on Tuesday April 11, 2017 @08:20PM (#14093723)
That's one option (my favorite and the simplest to use).

But the "default" is annotated JS which is not dissimilar to how TS operates.

I prefer Flow's syntax and if it wasn't for the annoying "you have to run a server to check code" thing... I'd use it a lot more

Re:TypeScript at Slack by jankassens on Wednesday April 12, 2017 @03:16AM (#14095487)
You can use `flow check`, but the server has the benefit of giving almost instant responses even on large code bases by only revalidating a subset of the project.
Re:TypeScript at Slack by abritinthebay on Wednesday April 12, 2017 @04:21PM (#14101363)
Yeah, there are ways to configure it to be better but it's just not... "nice" out of the box.

Which is sadly important - for something so optional.

Re:TypeScript at Slack by ng12 on Tuesday April 11, 2017 @08:20PM (#14093722)
But Flow is actually a superset of JS -- without the types your code is perfectly valid JS, which is what actually happens via a simple Babel transform. Typescript is both a transpiler and a language, it's much further from pure JS. The actual advantage of this is you can drop Flow in any Babel project. With Typescript you need additional tooling.
Re:TypeScript at Slack by Touche on Tuesday April 11, 2017 @08:58PM (#14093943)
They are both supersets. If you remove the non-JS features you have valid JS. But of course without removing it you have invalid JS. That's why both require tools.

Sidenote that Flow does allow specifying types through comments but this is a bit of a second-class feature.

Re:TypeScript at Slack by ng12 on Tuesday April 11, 2017 @10:14PM (#14094205)
Sorry, let me try to be more clear -- because this is a very real distinction which does have practical implications.

You can run Flow on ES code without changing it. If you have type annotations it will use them to help find errors, and you can use a simple tool to strip them out. The key thing here is that the "stripped" code is EXACTLY your source minus the type annotations. Typescript does not operate like this -- you cannot make assumptions about what the code looks like post-tsc. This is very important if you have some other tools, like Babel plugins, which operate on your code. You're likely to run into trouble if you want to use syntax Typescript doesn't understand or if a tool is doing some sort of code analysis.

Typescript is a language but Flow is much closer to a linter.

Re:TypeScript at Slack by spion on Wednesday April 12, 2017 @04:27AM (#14095814)
Sorry, Flow is a different language. The fact that it reuses a JS extension doesn't matter. Adding type annotations means that the language is no longer ES.next. The only reason Babel and the surrounding tooling understands it is because they, too, have been extended by Facebook to support said type annotations.

Try another ES.next tool, and it wont work. There are no type annotations in any ES spec.

Its the exact same thing, only MS is a bit more straight-forward about it (that its a different language). They are also siloed a bit more, perhaps - they could send a PR over to Babylon to add basic TS parsing support. But then they'd have to maintain that in sync with the original compiler.

If MS did what FB does, everyone would blame them for "embrace, extend, extinguish", pushing their own typed JS dialect by taking advantage of their influence in the JavaScript community, and falsely presenting it as "more JS" than the competing typed dialect.

I'm assuming FB have the best intentions, and I think they did it this way because they want to work with the existing open source community and standards bodies (avoid being siloed). But thats the only difference I can think of.

Ah, and yes, you can write all your types in comments. Thats a fair point. But it seems like they picked the most unergonomic way of doing this. The original extension supported this syntax

  /*: (x: string, y: number): boolean */
  function foo(x, y) {
    return x.length * y === 5;
  }
But thats gone, and current flowtype only supports this:

  function foo(x /*: string */, y /*: number */) /*: boolean */ {
    return x.length * y === 5;
  }
which is terrible to both write and read.
Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @12:02PM (#14098971)
I never said flow wasn't a different language or that it conformed to any ES spec.

> Its the exact same thing, only MS is a bit more straight-forward about it

This is what people are not understanding. Flow lints your code, then removes the types, leaving you with valid ES6 that is EXACTLY your source code without the types. Typescript is fundamentally different -- it transpiles your code and you cannot make assumptions about what that code looks like. They are not the exact same thing by any metric.

Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @03:29PM (#14100961)
Typescript lints your code, then removes the types, leaving you with valid ES2015 that is EXACTLY your source code without types when you target ES2015 and stick to writing ES2015.

Typescript's transpilations are primarily to downlevel "future" ES features to previous ES versions (just like Babel). In my experience you absolutely can make assumptions about what the code looks like, and I have never been surprised by Typescript's output.

Typescript and Flow are a lot the same. Typescript has a few more "Babel features" built in.

Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @03:56PM (#14101159)
This is demonstrably false. Typescript makes no guarantees about what the output looks like. Take this incredibly simple example:

   ~: cat test.ts
   class Foo {
      foo = () => console.log('Foo!')
   }
   ~: tsc --target es6 test.ts && cat test.js
   class Foo {
      constructor() {
         this.foo = () => console.log('Foo!');
      }
   }
The code is functionally the same but not identical, which like I said earlier can be an issue if you're using other tools which analyze/modify your code. I prefer Typescript over Flow for other reasons but the amount of misinformation in this thread is astounding.
Re:TypeScript at Slack by spion on Friday April 14, 2017 @07:42AM (#14113871)
Flow understands this code perfectly well too.

https://tryflow.org/?code=Y2xhc3MgRm9vIHsKICBmb28gPSAoKSA9Pi...

You get no errors.

Additionally, TypeScript's stated design goal is to not deviate from current or future EcmaScript [1]

You want more control over exactly what gets transpiled i.e. "I don't want to use ES.next, only ES6". Thats a valid point, but really far from your original assessment that there is a fundamental difference between the languages.

[1]: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi... - goal 6

Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @04:11PM (#14101285)
Your class is not syntactically valid ES2015. Typescript is allowing a shorthand that ES2015 doesn't allow and rewrites it to proper ES2015. It's a tiny babel plugin. Maybe a stricter output target should provide a syntax warning here.

The source conversion here, based on the implications of the shorthand, shouldn't be a surprising output and looks like perfectly readable, idiomatic JS to me.

Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @04:21PM (#14101360)
Can you turn of those transpilations though? Readable code isn't the problem, equivalence is. Flow will never rewrite anything, which is what I've been saying.
Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @04:49PM (#14101614)
Many of the transpilations you can turn off. The targets system turns off/on many transpilations as a suite. There are flags for several others such as `--noEmitHelpers`, `--preserveConstEnums`, `--jsx Preserve`.

If you have a reason to disallow and/or preserve something that TS does not already support, I would think the Typescript team would be interested in hearing about it.

Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @04:52PM (#14101629)
But the argument I'm making is it's disingenuous to say that Flow and Typescript are both equally "not Javascript". Flow is _strictly_ additive to whatever else your toolchain is. Typescript is a different language.
Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @05:28PM (#14101932)
I never said that Flow and Typescript are "equally" not JavaScript. I think you are getting your arguments crossed here.

Though I will state that both are not JavaScript, even if they are "unequally" not JS (for whatever that distinction means to you, though I think it is a moot point). Flow when used purely as comments is JS, sure, but the type annotation syntax is not JS as defined by any ES standard (except maybe ES4) nor any JS accepted by browsers (definitely not ES4). "Strictly additive" isn't a distinction that matters to what constitutes a language, if we want to be pedantic.

Finally, I would suggest you refrain from the word "disingenuous". Yes, my opinions differ from your own, but you cannot speak to the candor of my opinions here. I am hoping you did not intend an ad hominem attack, but I don't think a lot of people realize how much "disingenuous" is an ad hominem attack.

Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @05:32PM (#14101967)
> I never said that Flow and Typescript are "equally" not JavaScript. I think you are getting your arguments crossed here.

Read the rest of this thread, that is the point at hand. I'd generally suggest doing that before jumping in.

Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @05:47PM (#14102073)
I commented on a specific point you were making. Whether or not I read the rest of the thread is irrelevant to the discussion at hand.
Re:TypeScript at Slack by ng12 on Wednesday April 12, 2017 @06:23PM (#14102285)
So it's just an irrelevant interjection then? Your not wrong, I'm not wrong, we're just having two separate conversations.
Re:TypeScript at Slack by Touche on Tuesday April 11, 2017 @10:46PM (#14094316)
You're describing a property of their compilers as evidence that one is a superset and one is not. That TS transforms your code doesn't make it not a superset. It would not be a superset if it didn't support some JS feature. If it didn't support extends or something.
Re:TypeScript at Slack by ng12 on Tuesday April 11, 2017 @10:56PM (#14094366)
I'm not saying Typescript isn't a superset of JavaScript, I'm saying Flow is more direct superset in a way that's important. I'm more trying to clarify people who are saying Flow and TS are both supersets and therefore directly comparable. Specifically, the root poster's contention was that they're both supersets and therefore​ both "not JS".
Re:TypeScript at Slack by RyanCavanaugh on Tuesday April 11, 2017 @09:04PM (#14093963)
"without the types your code is perfectly valid JS, which is what actually happens via a simple Babel transform"

This is literally exactly the same amount of true for TypeScript as it is for Flow

Re:TypeScript at Slack by STRML on Tuesday April 11, 2017 @09:10PM (#14093991)
They're different. Flow is not a "superset" of JS in that it introduces new features, it only introduces new types of annotations. Remove all the annotations (literally delete them), and you have valid ES6.

Typescript has its own class system, public/private/protected, and its own compiler. This was a big negative while ES6 was still brand new and the TS compiler was catching up, but now it's pretty much a wash between the two.

A year ago, I would have said Flow, no question. Today, TS has really caught up and the tooling is better, no doubt. It depends on how complex your types are - Flow can express types TS can't, but TS has an incredible ecosystem and far fewer bugs. In the end, it's all about reducing bugs in your own application, and TS seems to do that better in the end despite its limitations.

Re:TypeScript at Slack by WorldMaker on Wednesday April 12, 2017 @03:35PM (#14101002)
The class system was already an EcmaScript proposal at the time Typescript adopted it, and what Typescript launched with was directly based on the ES proposal at the time. The proposal shifted a bit before it was finalized and TS did the necessary catch-up work to the final accepted specification. It hasn't added anything whole cloth other than types that wasn't in some stage or another an ES proposal. (From that perspective TS has always been Flow + a few curated Babel plugins.)
Re:TypeScript at Slack by woah on Wednesday April 12, 2017 @01:56AM (#14095142)
Not true. Typescript does all kinds of transforms. Flow does nothing except catch type errors, and then it is simply stripped out. Nothing else in the code is touched at all.
Re:TypeScript at Slack by ng12 on Tuesday April 11, 2017 @10:16PM (#14094209)
See my comment above, but this is not true. The output of the type stripping is exactly your code without types. This is not true for Typescript.
Re:TypeScript at Slack by smt88 on Tuesday April 11, 2017 @07:56PM (#14093578)
I like that Flow is basically comments, rather than a new language. You can add comments to an existing code base and discover lots of bugs.

I don't think there are too many negatives with that system, although I will say having the type system deeply integrated with the debugger in TS is great.

I'll also say that while TS tooling is better, it can (sometimes) be really complicated to set up and understand.

Re:TypeScript at Slack by simplify on Tuesday April 11, 2017 @07:21PM (#14093392)
I feel the same way. I'm eager to use Flow, but their tooling is just so far behind. Until it catches up I'm using TypeScript, which is much, much better than nothing :)
Re:TypeScript at Slack by BinaryIdiot on Tuesday April 11, 2017 @08:05PM (#14093634)
> What's more interesting to me is that everyone who converts their code into Flow or TS immediately finds at least N bugs (albeit small).

When I was playing with TS I converted a project and found no additional bugs. Type related bugs shouldn't be that common IMO (if they are and they're systemic (not like a one off) I would argue that there is an issue with the way you're architecting).

Maybe TypeScript just isn't for me. I see its value but didn't find it high enough to continue using. I'm working on creating a .d.ts file for one of my open source libraries but I don't know that I'll use it beyond that anytime soon.

Re:TypeScript at Slack by chickenfries on Tuesday April 11, 2017 @08:37PM (#14093827)
To me, the value is at design/write time, not in converting old code. Old code that already works correctly will not be made more correct with TS unless you have branches of code that haven't been tested (by you during development, in tests or by your users). Working TS just lets me catch type mismatches while I'm writing instead of after the whole build process has run and I've reloaded the browser.
Re:TypeScript at Slack by zip1234 on Tuesday April 11, 2017 @09:27PM (#14094055)
Also don't forget refactoring. Try renaming a property with confidence in plain JS. In TS it is simple.
Re:TypeScript at Slack by michaelmcmillan on Tuesday April 11, 2017 @10:40PM (#14094293)
No problem if you test your code, as you should.
Re:TypeScript at Slack by recursive on Wednesday April 12, 2017 @12:17AM (#14094716)
Somehow, a failing test isn't quite as convenient as a reliable renaming operation.
Re:TypeScript at Slack by michaelmcmillan on Wednesday April 12, 2017 @12:49AM (#14094846)
Granted, but a renaming option is just that. A test will not only provide confidence, but also tell you if the code contains a logical bug.
Re:TypeScript at Slack by throwaway9475 on Wednesday April 12, 2017 @01:09AM (#14094926)
No, a test will tell you whether or not that test passes; it says nothing about the correctness of anything else. But at this point, you're doing the job of a typesystem.
Re:TypeScript at Slack by michaelmcmillan on Wednesday April 12, 2017 @01:48AM (#14095095)
> No, a test will tell you whether or not that test passes; it says nothing about the correctness of anything else.

That is a tautology: Of course a failing test shows you that the test failed. However, your test suite is severely flawed if the type system makes it redundant.

Re:TypeScript at Slack by guscost on Wednesday April 12, 2017 @08:46AM (#14097082)
There's a whole class of type mismatch bugs, which can show up in one or more code paths of just about any practical program, and which can be eliminated by a type checker (instantly in your text editor if you set it up, or at compile time). If you are writing and maintaining tests for lots of these bugs, you should consider adding a type checker to do it for you. The difference in overhead between annotating a variable and writing a test is huge.
Re:TypeScript at Slack by michaelmcmillan on Thursday April 13, 2017 @04:07AM (#14105066)
Which, again, proves my point: If your test suite can be reduced to a type checker you are doing it wrong. That being said, it does not mean that a type checker won't catch many of the same bugs tests do - but no more than a subset.
Re:TypeScript at Slack by guscost on Thursday April 13, 2017 @08:58AM (#14106407)
Yes, good tests is the only way to eliminate most bugs. But aside from overhead to add tools to a project (don't underestimate the potential difficulty of this), a type checker can cover its subset for free, and then you can get better test coverage overall.
Re:TypeScript at Slack by ng12 on Tuesday April 11, 2017 @08:15PM (#14093689)
Yeah, I think the bug-finding value is overblown. I advocate Typescript entirely for developer experience. It lets me codify complex domain objects and will catch the obviously wrong bugs while I'm developing -- things like passing arguments in the wrong order or passing an x to a function instead of a y. Not to mention with Webstorm or VSCode you have actually reliable autocomplete too.
Re:TypeScript at Slack by andrewchambers on Tuesday April 11, 2017 @11:03PM (#14094390)
> What's more interesting to me is that everyone who converts their code into Flow or TS immediately finds at least N bugs (albeit small).

Just rereading all your code carefully (which porting generally requires) generally finds a few bugs in my opinion. It might not always be because of typescript.

Re:TypeScript at Slack by wyaeld on Tuesday April 11, 2017 @11:12PM (#14094439)
It doesn't port anything. Valid JS is valid TS, its just that the TS compiler processes it and tends to surface issues that just running it under Nodejs doesn't