News for hackers. Stuff that matters.
Re:Future of TypeScript on ESLint by _robbywashere on Friday January 18, 2019 @03:00PM (#18942450)
It's very nice to see all of this consolidation going on in the Typescript ecosystem. For example Babel 7 shipping with direct Typescript support back in August, https://blogs.msdn.microsoft.com/typescript/2018/08/27/types...

I am a Typescript convert myself and would suggest any daily JS developer give it an honest try.

Re:Future of TypeScript on ESLint by burtonator on Friday January 18, 2019 @04:15PM (#18943173)
Typescript is amazing!

I spent the last 90 days porting about 350k lines of code to Typescript plus implementing another 400k.

https://getpolarized.io/

It's basically a document and annotation manager for PDF and notes. Kind of an Open Source Mendeley/Evernote/Github if you will.

This code base is changing often and I really hit a dead in in terms of JS scalability.

I was just refactoring too much, breaking things, etc.

Now I can just rely on the compiler when I break things.

If I want to change a function type in TS it's no problem.

In JS it's a nightmare.

Re:Future of TypeScript on ESLint by oh_sigh on Friday January 18, 2019 @08:14PM (#18944619)
4000 LOC a day, every day, for 3 months? I hope that's a lot of boiler plate!
Re:Future of TypeScript on ESLint by idontpost on Friday January 18, 2019 @08:38PM (#18944710)
Depends on his coding style.

You can write Typescript like Java. You can also write it (almost) like Clojure. It's really very flexible, but without most of the insanity that flexibility causes in normal JS.

Re:Future of TypeScript on ESLint by Scarbutt on Friday January 18, 2019 @09:22PM (#18944909)
Typescript has a standard library like clojure for manipulating data? like the lodash of the JS world.

I would be surprised (without golfing of course) if typescript can match clojure's conciseness.

Re:Future of TypeScript on ESLint by idontpost on Sunday January 20, 2019 @08:07PM (#18956748)
I didn't say it could match it. I don't think it can, but you can write it very concisely if you choose to.

There's not a big difference in concisesness or readability between Clojure threading macros and JS promise chaining, for example:

(-> (do x) then-do-y then-do-z then-do-q)

vs

doX() .then(doY) .then(doZ) .then(doQ);

Of course, the Clojure version is more flexible, and the ability to define DSLs very simply allows for further conciseness, but that's all beside the point. My point is just that Typescript can be written very concisely or very verbosely, depending on your own coding style.

Re:Future of TypeScript on ESLint by dragonshed on Saturday January 19, 2019 @03:04AM (#18945920)
No, typescript adds as little as possible to support its language features. You'll need to rely on js libraries or browser features for the API.
Re:Future of TypeScript on ESLint by jfaat on Friday January 18, 2019 @07:12PM (#18944327)
This looks awesome, going to check it out this weekend!

FYI in a narrow (especially < ~1000px) the Features icons are overlapping content. I tried changing the class 'fa-4x' to 'fa-2x' on those icons and it appears to fix the issue.

Re:Future of TypeScript on ESLint by netcraft on Friday January 18, 2019 @06:31PM (#18944122)
Any chance you would ever add RSS capabilities?
Re:Future of TypeScript on ESLint by burtonator on Friday January 18, 2019 @06:45PM (#18944199)
Thinking about it actually but for now worried about feature creep. We will see though.

I was actually one of the original inventors of RSS 1.0 and was on the working group.

http://www.datastreamer.io/

Is my other company and we have about a petabyte of content ... so definitely familiar with the space.

I'm trying to look at things a bit differently now though. I have a bunch of ideas I'm going to experimenting with.

Re:Future of TypeScript on ESLint by burtonator on Friday January 18, 2019 @06:50PM (#18944232)
Actually might just implement it because you guys at Hacker News will upvote me into the stratosphere ;)
Re:Future of TypeScript on ESLint by Scarbutt on Friday January 18, 2019 @09:19PM (#18944895)
So you did 750 thousand lines of code in 90 days? impressive.
Re:Future of TypeScript on ESLint by misiti3780 on Friday January 18, 2019 @04:17PM (#18943191)
your project is amazing, i would love to help contribute as i have time. please reach out if you need development help.
Re:Future of TypeScript on ESLint by burtonator on Friday January 18, 2019 @05:18PM (#18943627)
Definitely always need help even if it's just feedback on releases.

The issue tracker is a good place to start looking :)

Re:Future of TypeScript on ESLint by jondubois on Saturday January 19, 2019 @06:33AM (#18946485)
WTF. The project seems completely useless and gimmicky to me.

My problem is that I read a LOT of articles and publications. If I started highlighting things in articles, I would never have enough time to go back to them. Besides, why would I want to? I already read it, which means that it's already in my mind! What's the point of reading stuff if not to put information inside your mind? I'd rather use my time to read more new stuff than to revisit things I already know.

Maybe the solution is not more tools, it's just to stick to topics that interest you and to pay attention and put more thought into what you're reading.

Re:Future of TypeScript on ESLint by misiti3780 on Saturday January 19, 2019 @02:51PM (#18948828)
maybe you should be a little less critical about someone who actually built something extremely useful and spend some time investigating the topic of "incremental reading" -- reading info and retaining info are two different things

https://www.supermemo.com/help/read.htm

Re:Future of TypeScript on ESLint by jondubois on Sunday January 20, 2019 @04:48AM (#18952210)
>> reading info and retaining info are two different things

I apologize, I projected my own experience and assumed that other people were able to remember the main points of what they read. I guess most people don't have have great memory. I never thought of myself has having good memory but I remember the main points of most of what I read.

Re:Future of TypeScript on ESLint by misiti3780 on Friday January 18, 2019 @04:27PM (#18943268)
also, looking for an answer to this question :)

https://www.reddit.com/r/PolarBookshelf/comments/ah1g5w/what...

Re:Future of TypeScript on ESLint by 5Qn8mNbc2FNCiVV on Friday January 18, 2019 @05:27PM (#18943703)
Oh my god, getpolarized is exactly what I am currently trying to achieve. I tried out PDF.js to get highlighting and reading progress in my application but could never figure it out. This is amazing!!
Re:Future of TypeScript on ESLint by burtonator on Friday January 18, 2019 @06:46PM (#18944205)
Nice!! glad you approve! Jump on the Discord if you have any questions.
Re:Future of TypeScript on ESLint by celestialjeu on Friday January 18, 2019 @03:12PM (#18942585)
Have you used flow at all in the past? If so what would you say the major differences are/how difficult was any process to convert over? I'm a huge fan of having the types defined just from a documentation perspective nevermind bug catching and debugging and all that. I feel relatively agnostic about the particular thing we use to do it so I'm curious as to what the differences are.

But yeah it really has improved my day to day immensely and I really feel the difference when I'm working in legacy portions of our apps that pre-date the flow adoption.

Re:Future of TypeScript on ESLint by jameslk on Friday January 18, 2019 @03:41PM (#18942858)
I have used both TypeScript (for multiple projects) and Flow (at Facebook). TypeScript is much more feature-rich and looser in strictness. In practice, this looseness has been preferable, as I've seen many of my colleagues fighting Flow's type system vs TypeScript (prior to FB). In theory, perhaps Flow's type system prevents more bugs, but I've sometimes seen it circumvented with hacks just to get past its strictness. TypeScript's ability to infer types seems much smarter than Flow's as well.

Besides that, TypeScript has much wider adoption and community support. Most issues I have with TypeScript I can find others who have had similar issues on the web, where as I can't say the same about Flow.

Re:Future of TypeScript on ESLint by lhorie on Friday January 18, 2019 @07:49PM (#18944521)
There's been a lot of doubt cast on Flow outside of Facebook when Jest announced it was moving to TS.

I'm curious to hear how Typescript vs Flow discussions go within Facebook, and what engineers there think of each.

Re:Future of TypeScript on ESLint by ajbogh on Tuesday January 22, 2019 @07:15PM (#18974338)
I would also like to know how many projects within Facebook, if any, use Typescript. I'd be interested in the growth rate as well (how many projects over time).
Re:Future of TypeScript on ESLint by _robbywashere on Friday January 18, 2019 @04:06PM (#18943087)
I have never used Flow beyond a basic hello world. The syntax is very similar. Some of the nomenclatures vary. All and all they will both accomplish 99% of the same thing - statically typing a dynamic language. Which gives you much more code confidence, `foobar is undefined` is very less likely. self-documenting code. (see: vs-code intellisense) And code maintenance scale abilities currently not possible with such a loose language like javascript.

So I would say if you're interested pick one and dive in.

Right now typescript has a lot of community momentum: https://github.com/DefinitelyTyped/DefinitelyTyped

And an extremely fast, open sourced, plugin enabled editor, vs-code ftw! I am a convert after being a longtime diehard vim user. (vs-code has the best vim binding emulation I have ever used in a free open sourced editor)

Facebook is deprecating their flow atom editor plugin; nuclide - https://twitter.com/fbopensource/status/1072928679695548416?...

This is all why I would choose typescript over flow if it were up to me. maybe a flow user can chime in.

Re:Future of TypeScript on ESLint by AgentME on Friday January 18, 2019 @05:11PM (#18943586)
I've used Flow very heavily and TypeScript a reasonable amount. They're pretty similar really, but I'd recommend TypeScript for its better tooling and larger available set of type definitions.

Flow doesn't seem to be built with the (non-Facebook) developer experience in mind. It very frequently has breaking changes. The tooling is worse. There's no good official way to publish a package to npm with Flow type definitions included. Its alternative to DefinitelyTyped requires using their own CLI tool instead of copying DefinitelyTyped's simple npm-based strategy.

There a few things Flow does better. Functions internal to a file often don't need their parameters to be typed because Flow infers their types, but honestly I don't think that's a very killer feature. I often type them anyway just to be explicit. Flow does model type variance better (a Promise<{a:string,b:string}> can be cast to Promise<{a:string}>, but not vice versa, and you can't do the same with mutable arrays, etc.) but variance doesn't come up often and you can always use the any-type escape hatch in TypeScript to make it through those uncommon situations. I do hope TypeScript gets better about that though.

Flow isn't bad; a Flow codebase is still much better than an untyped Javascript codebase. But if you're starting a new project and have the choice, pick TypeScript.

Re:Future of TypeScript on ESLint by williamdclt on Friday January 18, 2019 @05:41PM (#18943812)
Agree on 100% of this.

Also errors in Flow are often very esoteric. The "smarter inference" sometimes made type errors appear in the callee rather than the caller (having an error on React's component type definition is not helpful). The wording isn't user-friendly if you're not familiar with typing theory.

Inference is not that much of a killer feature I feel: I don't want the type to be inferred based on how I use a variable, I want to check that I don't misuse the variable based on its type. Obviously there's use for inference too, but in the general case...

Re:Future of TypeScript on ESLint by chrisweekly on Friday January 18, 2019 @10:33PM (#18945153)
Also, if you're looking to introduce types to an extant Javascript project, there's a good chance you're already using babel. That used to be a (slight) point in flow's favor, but as of Babel 7, you can opt to have Babel transpile your TypeScript. Not that there's anything wrong with tsc. :)
Re:Future of TypeScript on ESLint by ng12 on Friday January 18, 2019 @05:10PM (#18943584)
Typescript's tooling is much better -- it's just a JS transpiler (and now you can use babel to do your transpiling if you prefer). Flow's daemon-style approach was a constant source of pain for me.
Re:Future of TypeScript on ESLint by AgentME on Friday January 18, 2019 @05:13PM (#18943600)
Flow operates very similarly: the recommended setup is to use it with Babel. Babel just strips out the type annotations from your code to make it into legal javascript. The Flow daemon executable was just to provide type checking. Before TypeScript also got similar Babel support, I considered it a strong point in Flow's favor that it was so easy to drop in if you already had a Babel setup going.
Re:Future of TypeScript on ESLint by ng12 on Friday January 18, 2019 @05:20PM (#18943643)
> The Flow daemon executable was just to provide type checking.

This is problematic. Now your webpack build is shelling out asynchronously to a second process. It makes it very hard to integrate type checking to a build system.

Re:Future of TypeScript on ESLint by AgentME on Friday January 18, 2019 @05:28PM (#18943706)
I've never connected Flow to webpack or my compile process like that. When I've used Flow or TypeScript with Babel, the build process and type checking were always two separate things. I treated type checking like unit tests: something I'd frequently re-check while working on code, but not something connected to the path of getting code running somewhere.
Re:Future of TypeScript on ESLint by ng12 on Friday January 18, 2019 @05:29PM (#18943719)
Don't you want your build to fail if the type checker fails? I think it's pretty important for a large project.
Re:Future of TypeScript on ESLint by williamdclt on Friday January 18, 2019 @05:44PM (#18943830)
Not necessarily locally. On CI/staging/prod yeah definitely, but when I'm hacking around I'm fine with having type errors ("yeah yeah I know this is nullable, I don't care right now I just want to investigate this bug")
Re:Future of TypeScript on ESLint by nrb on Friday January 18, 2019 @09:09PM (#18944853)
I absolutely want it locally, preferably inside my IDE where it's providing type hints, allowing navigation to type declarations, and alerting me immediately to typing issues live as I'm coding.
Re:Future of TypeScript on ESLint by williamdclt on Saturday January 19, 2019 @05:28AM (#18946321)
Of course I want the type checking locally, what we mean is that we don't want it to prevent webpack to build if the typecheck fails
Re:Future of TypeScript on ESLint by munchor on Saturday January 19, 2019 @01:51AM (#18945713)
Flow gives you all of that. The fact that the type checker is separated from the emitter does not mean you can't get any of that.
Re:Future of TypeScript on ESLint by AgentME on Friday January 18, 2019 @06:17PM (#18944058)
I don't really feel strongly about it, though sometimes Flow takes 10+ seconds to re-check a large project I work on after changes, and I wouldn't want building to have to wait on that. (I've never worked on a similarly-sized project in TypeScript, but I expect it's about the same situation.) I usually use a CI system (CircleCI) which sends me an email if any of my commits don't pass type checking or unit tests, and it flags any PRs on Github that fail too.
Re:Future of TypeScript on ESLint by root_axis on Friday January 18, 2019 @07:17PM (#18944349)
Only in CI, not during development. IDE warnings are enough.
Re:Future of TypeScript on ESLint by 4lejandrito on Friday January 18, 2019 @06:31PM (#18944125)
I found this post quite interesting. These guys migrated a big codebase from flow to typescript. https://davidgom.es/porting-30k-lines-of-code-from-flow-to-t...
Re:Future of TypeScript on ESLint by PhineasRex on Saturday January 19, 2019 @07:13PM (#18950109)
I've deployed flow extensively and the biggest difference is that flow is horribly buggy (lots of false negatives) while typescript is mature. In theory flow's type system is stronger but it's so unreliable that 99% of the time I'd rather use typescript.
Re:Future of TypeScript on ESLint by fibo on Saturday January 19, 2019 @01:42PM (#18948452)
The main issue I found with flow is importing type packages.
Re:Future of TypeScript on ESLint by pjmlp on Friday January 18, 2019 @03:40PM (#18942837)
A tiny part of me still hopes that one day JS standard adopts 100% of TypeScript features.
Re:Future of TypeScript on ESLint by AgentME on Friday January 18, 2019 @06:31PM (#18944128)
Official support would make it hard for it to ever have any breaking changes though. I think I'd like to give TypeScript more time before risking putting any of it in stone.
Re:Future of TypeScript on ESLint by bauerd on Friday January 18, 2019 @03:44PM (#18942886)
Is JS a strict subset of TypeScript?
Re:Future of TypeScript on ESLint by steadicat on Friday January 18, 2019 @03:52PM (#18942953)
Yes. All JS code – including recent ES* flavors – is valid TypeScript.
Re:Future of TypeScript on ESLint by thomasfoster96 on Friday January 18, 2019 @06:41PM (#18944177)
This is true of syntax, but it’s not true of the language semantics. There is plenty of perfectly valid JavaScript that isn’t valid TypeScript, so integrating TypeScript into the ECMAScript standard would require something similar to ES5’s “use strict”.

I can’t find the link which details this right now, but I believe there are/were some cases where Flow’s syntax isn’t strictly a superset of JavaScript (to do with generics and comparison operators). I’m not sure whether TypeScript has the same problem or not.

Re:Future of TypeScript on ESLint by recursive on Friday January 18, 2019 @06:37PM (#18944160)
Almost. This is valid javascript.

    [1].push("foo");
Re:Future of TypeScript on ESLint by alangpierce on Friday January 18, 2019 @07:00PM (#18944279)
TypeScript code can be transpiled and executed even if there are type errors (just like how a linter doesn't stop you from running your code), so in that sense, it's also valid TypeScript.
Re:Future of TypeScript on ESLint by tazard on Friday January 18, 2019 @06:28PM (#18944112)
Technically typescript is a strict superset of JS, but yes
Re:Future of TypeScript on ESLint by lhorie on Friday January 18, 2019 @07:39PM (#18944467)
Technically technically, it turns out that no it's not. I recently realized that `a<b>(x)`, `a<b,c>(x)` and variations mean something completely different in TS than they do in JS.
Re:Future of TypeScript on ESLint by chrismorgan on Saturday January 19, 2019 @04:33AM (#18946168)
And that’s exactly why Rust has the turbofish (a :: before the <), to resolve that syntactic ambiguity. TypeScript could have resolved it by requiring a . before the <, but it didn’t, and so you can devise contrived cases like this where it differs from JavaScript.
Re:Future of TypeScript on ESLint by spraak on Friday January 18, 2019 @11:32PM (#18945346)
Is that denoting generics? Can you give an example?
Re:Future of TypeScript on ESLint by alangpierce on Friday January 18, 2019 @11:58PM (#18945416)
Yeah, it's the syntax when calling a generic function, e.g. `Array.of<number | null>(1, 2, null);` has return type `Array<number | null>`. You usually don't need to specify the type since TypeScript can figure it out, but sometime's it's necessary to specify it explicitly.

TypeScript compiles `a<b>(x)` to `a(x)`, which is a function call, but when run as plain JS, `a<b>(x)` is a less-than and greater-than comparison between a, b, and x.

Re:Future of TypeScript on ESLint by tazard on Sunday January 20, 2019 @09:57AM (#18953303)
That's interesting and so obvious now that you mention it. Thanks for the clarification.
Re:Future of TypeScript on ESLint by atombender on Friday January 18, 2019 @05:19PM (#18943640)
How's the migration path? I use TypeScript for new React apps I build, but I'm dealing with some JS projects where there's just no way to convert everything to TS all at once.

Does TS work well alongside legacy JS so you can update individual files incrementally as you go along? I remember trying it once and facing some unexpected blockers, but I don't remember what they were.

Re:Future of TypeScript on ESLint by ng12 on Friday January 18, 2019 @05:27PM (#18943695)
It's very seamless. There's a flag, allowJs, that lets you import js files with only sanity checks (no actual typechecking). You can then start converting individual files to Typescript as you go.
Re:Future of TypeScript on ESLint by atombender on Friday January 18, 2019 @05:38PM (#18943788)
Thanks! I wish I could remember what I ran into the last time. I guess I'll just have to try.
Re:Future of TypeScript on ESLint by addicted on Friday January 18, 2019 @07:41PM (#18944482)
I believe the allowJS flag is new and disabled by default. It may not have existed when you last tried. That’s what happened with our team. We tried to switch in either 0.x or low 1.x and at the time I believe we had to convert everything to TS (although, we may just not have been aware of the allowJS flag at the time).
Re:Future of TypeScript on ESLint by 52-6F-62 on Friday January 18, 2019 @04:12PM (#18943136)
I'm 100% with you. I find it far more sane, and encourages better practices (in my case).

When I'm responsible for tooling in a JavaScript project, it's pretty well a given that I'll push for TypeScript.

Re:Future of TypeScript on ESLint by mirekrusin on Friday January 18, 2019 @03:17PM (#18942624)
I still feel better with thin/no tooling for transpiling, flow types in comments. There’s something nice about no or ultra flat dependencies and instant npm i that keeps me there.
Re:Future of TypeScript on ESLint by nevir on Friday January 18, 2019 @03:39PM (#18942835)
Typescript also supports type checking pure JS files, as well as type annotations via JSDoc comments, if you don't want to transpile.
Re:Future of TypeScript on ESLint by mifreewil on Friday January 18, 2019 @03:44PM (#18942881)
Re:Future of TypeScript on ESLint by h1d on Friday January 18, 2019 @06:05PM (#18943983)
I like how TS also enables future JS features by transpilation. async / await was great to have quite early on.
Re:Future of TypeScript on ESLint by lisowski on Friday January 18, 2019 @05:50PM (#18943872)
If you use VSCode just put `// @ts-check` at the top of your files. I find a bunch of bugs with just that.
Re:Future of TypeScript on ESLint by mLuby on Friday January 18, 2019 @03:44PM (#18942890)
100%! Whatever happened to progressive enhancement?
Re:Future of TypeScript on ESLint by munchbunny on Friday January 18, 2019 @04:42PM (#18943381)
It's a design trade-off. TypeScript is close enough to JavaScript but adding the compiler step actually enables worthwhile changes to improve code safety. And Typescript can import JavaScript modules anyway, so really you just lose the ability to write both in the same file.
Re:Future of TypeScript on ESLint by coldtea on Friday January 18, 2019 @05:27PM (#18943701)
I'd like to see at some point browsers treating TS as a typed JS variant, and using the hints to speed up things perhaps too.
Re:Future of TypeScript on ESLint by nicoburns on Friday January 18, 2019 @08:04PM (#18944579)
I think if you make things consistently typed (as typescript will help enforce), then your JS will run faster already. Because a lot of techniques JS JITs use are basically guessing the type of variables, and then bailing out into a slow path if it turns out they guessed wrong. Codebases like lodash make use of this, which is one reason why they're so fast.
Re:Future of TypeScript on ESLint by h1d on Friday January 18, 2019 @06:02PM (#18943960)
Would be nice if Chromium picks it up which can be propagated to Chrome and Safari on desktop and mobile and Edge then to nodejs and others will surely pick it up if those adopt it.
Re:Future of TypeScript on ESLint by koolba on Friday January 18, 2019 @09:05PM (#18944834)
That’d be terrible as the language version changes semantics.
Re:Future of TypeScript on ESLint by coldtea on Saturday January 19, 2019 @07:48AM (#18946761)
So same as with plain JS?