Live data from Hacker News

I Was Wrong About TypeScript

triplet.fi

81–90 of 194 posts

Re: I Was Wrong About TypeScript

#81
post #76

Earlier quoted context omitted.

It's not a problem. You can resort to any type and works with 3rd party stuff like with normal JS code.

Yes, I can write my own types, but typing isn't always easy. Especially with advanced techniques like parametric polymorphism etc.

No, I think solomatov is saying you can always use the 'any' type built-in to TypeScript. You can always do:

    declare var fancyNewLib: any;

    fancyNewLib('hello');
    fancyNewLib.someCoolFeature = 3;
You don't get any suggestions or typechecking (obviously), but you're no worse off than just using JS in that sense. And you can easily replace your 'declare' with the actual // tag when you find it or make it, and clean up any errors.

Re: I Was Wrong About TypeScript

#82
post #55

Ashamedly at one point I was on the anti-Angular 2 bandwagon due to Typescript, because Microsoft. When I started learning Angular 2 myself I've found I actually enjoyed working with Typescript, for many reasons. (confidence that my code wasn't a ball of mystery before it ran, using inline templates, succinctness of annotations, etc) At the same time, you're gonna need to use some preexisting libraries, and run into…

Ha, I'm on the anti-Angular2 bandwagon due to Angular1. I use React and Typescript and love it. Curious if you've tried React. Or Angular1 (TBH Angular1 was pretty great at the time, but after React I look back at those monstrous template files, ng-everything, plugins and workarounds, and only the bad memories surface).

I'm interested to know if you can build a hybrid app using just React?

I tried React but I hit a wall of needing synchronisation, routing, notifications, can you do that now?

Re: I Was Wrong About TypeScript

#83
post #64

Earlier quoted context omitted.

I can't go with that. Anders H is one of the most avuncular, helpful and accessible voices out there. Oh and his very verbs twinkle!

Well, I just saw a talk about TypeScript 2 and it felt to me that he was belittling JavaScript.

If you've ever worked with a strongly typed language you can't but belittle JavaScript ;)

Re: I Was Wrong About TypeScript

#84

I just can't justify writing my team's code base in typescript. I don't want to make that move, setting us down a very specific path. I don't want to add another layer of training to develop on our codebase, but mainly, I just don't have the confidence that it's a right or wrong choice, and its a big choice. But I get a sense that it would be great to try for smaller, disposable projects as that's limited risk. Does…

I wrote in a previous post that I enjoy working with Typescript and overall it's a win for our team, but these days I sometimes wonder how much of a win over es6/7. I've found the biggest headache is getting all the *.d.ts files setup right and setting up your own types can sometimes be a pain, but as I mentioned it's pretty opt-in.

You don't use TS because of the ES6 features. If that's your goal then you can simply stick with babel. You use TS because of the type checker, and that will not be part of ES6/7.

Re: I Was Wrong About TypeScript

#85
post #76

Earlier quoted context omitted.

Yes, I can write my own types, but typing isn't always easy. Especially with advanced techniques like parametric polymorphism etc.

No, I think solomatov is saying you can always use the 'any' type built-in to TypeScript. You can always do: declare var fancyNewLib: any; fancyNewLib('hello'); fancyNewLib.someCoolFeature = 3; You don't get any suggestions or typechecking (obviously), but you're no worse off than just using JS in that sense. And you can easily replace your 'declare' with the actual // tag when you find it or make it, and clean up an…

Ah, yes, that's what I'm doing most of the time. But like you said it's no better than using JS directly, haha.

Re: I Was Wrong About TypeScript

#86
post #7

I prefer frameworks that focus on pure javascript because the ones that don't tend to allow you too use javascript but have sparse documentation on how to use it effectively, instead focusing on typescript. When I first tried Angular 2 their javascript "hello world" example wouldn't even work, it was some bug in their site. I already need to use all sorts of other tools and abstraction layers when building websites/a…

I don't really work in the Javascript ecosystem, so when learning Angular 2 recently, I found all the other tools to carry far more cognitive load than Typescript.

The great irony of this (and fwiw, I completely agree, and I work on the angular core team...) is that by embracing platform features in ng2 we've opened up a mess of other issues to learn.

A good example of this is modules. Angular 1 had its own module syntax (partly because modules weren't really a thing when it started). You could write scripts, concat them together and go.

In angular2 we embraced ES6 modules, which means a developer has to deal with loading and bundling etc.

One nice side effect here though is we can leverage more tooling from the rest of the JS community (eg, the great work of webpack) rather than having angular-specific solutions.

Re: I Was Wrong About TypeScript

#87
Are there any patterns / recommended practices for unit testing Typescript. I recently joined a project which uses Angular1 + Typescript and had to introduce unit testing to the code base and it has been painful. A lot of backend API calls (wrapped in services) are being (chained and) invoked in the constructor. Any initialization is being squashed into the constructor. This makes setup of karma tests extremely painful/brittle without a complete refactor for each component. However wrapping initialization code in public methods feel strange to me. Any suggestions?

Re: I Was Wrong About TypeScript

#88
post #38

Earlier quoted context omitted.

I'd suggest using the --outDir option, so TS writes the .js files to a different directory which you can easily blow away.

Rob is exactly right that you should use --outDir You should aim for deployment process where outDir would be in .gitignore and building of the JS files would happen on a build server.

If you use --outDir, wouldn't the .js files that import the transpiled .ts files need to point to outDir instead?

This is the kind of stuff that makes the "incremental" adoption argument hard for me to swallow. If I can't rewrite a .js file to .ts without any further ripple effects within the project, then it's not truly incremental.

I wrestled with this stuff last week and ultimately ended up going with flow since it gave me type checking _and_ incremental adoption, without complicating my existing babel/webpack stack.

Re: I Was Wrong About TypeScript

#89
post #55

Ashamedly at one point I was on the anti-Angular 2 bandwagon due to Typescript, because Microsoft. When I started learning Angular 2 myself I've found I actually enjoyed working with Typescript, for many reasons. (confidence that my code wasn't a ball of mystery before it ran, using inline templates, succinctness of annotations, etc) At the same time, you're gonna need to use some preexisting libraries, and run into…

Ha, I'm on the anti-Angular2 bandwagon due to Angular1. I use React and Typescript and love it. Curious if you've tried React. Or Angular1 (TBH Angular1 was pretty great at the time, but after React I look back at those monstrous template files, ng-everything, plugins and workarounds, and only the bad memories surface).

The real decision re: NG2 v React is more about opinionated frameworks v non-opinionated frameworks. If you're by yourself and/or have tight control over all of your libraries, React is fine. If you're a bigger operation and need to trust the restrictions of the framework, NG2 is possibly a better choice.

Re: I Was Wrong About TypeScript

#90
post #45

Earlier quoted context omitted.

TypeScript 1.8 already has unions and custom type guards! You can use them today. Woohoo! (Looking forward to those non-nullable types, though.)

I was just about to complain how TS fails totally for typechecking backbone models or immutablejs datastructures: both situations where obj.get("foo") and obj.get("bar") return a particular type but there's no way of having TS handle that except defining them as any. But it turns out string literal types in 1.8 will make that work. And this was out since February! I should reevaluate TS for my omniscient project.

IIRC there is no ergonomic way to define typed records for Immutable.js ?
Post reply on HN