Live data from Hacker News

TypeScript support added to Create React App

github.com

81–90 of 90 posts

Re: TypeScript support added to Create React App

#81
post #12

Earlier quoted context omitted.

> There are no downsides but so many upsides I've not used TS, but from what I've read the types from TS are not js compatible, so once you go into TS you have code that just isnt js. (As opposed to flow, where you can just have it not be used) While transpiling is normal, I'm as hesitant to tie myself to TS as I am to, say, a non-standard decorators syntax. Anyone coming to me with "there are no downsides" in such a…

I'm not sure what you mean by "not JS compatible" here. TypeScript obviously compiles into JavaScript, and any valid JavaScript is also "valid" compilable TypeScript (the compiler will complain, but it will still compile it into JavaScript that does the same thing). With the right assertions (and @ts-ignore where necessary), you can even get the compiler to stop complaining! TypeScript does have some differences beyo…

Also, even namespaces and enums aren't that foreign, and are still "JS compatible" in that they transpile to perfectly normal JS code that you can still use quite obviously in other JS code (enums create a list of constants and sometimes a reverse lookup map; namespaces create ugly, nested, mergeable object literals and IIFEs just like Grandma jQuery used to bake back in the bad old days before module systems). From one point of view they are nothing but syntactic sugar for common JS patterns.

Re: TypeScript support added to Create React App

#82
post #24
post #5

Earlier quoted context omitted.

I'd call that a good thing, really. Not needing ever more dependencies. I think this is a solid direction to go. Let's just say I give the React devs... props.

Funny, cause just using typescript to compile means you get to drop a lot of Babel dependencies / eslint dependencies.

There's still react-scripts-ts [1] which drops the majority of Babel in the CRA pipeline for solely Typescript. Presumably, it will remain active as it is still a useful alternative if you know you are going to want Typescript from day one. (This Babel-based support is perfect for those unsure and looking to experiment, which is great.)

[1] https://github.com/wmonk/create-react-app-typescript

Re: TypeScript support added to Create React App

#83

I'd love to use TypeScript, but I've hit walls of errors that are nearly as bad as the old C++ template errors! (Though to be fair, this was a while ago, the compiler may have improved). SO: Any good way to learn TypeScript, particularly the more complicated types?

What sort of errors are you running into, and what project setup are you using? If you're using Create-React-App-TS, that's a separate fork of CRA 1.x that adds TS support, and has _horribly_ restrictive lint rules (many common style practices are treated as _compile_ errors). See https://github.com/wmonk/create-react-app-typescript/issues/... for discussion. (I ran across this while trying to set up a TS project for…

Thanks! I'll give it a go... I was trying with CRA, with the older compiler.

Re: TypeScript support added to Create React App

#84
post #78
post #76

Earlier quoted context omitted.

"Irresponsible" is a bit of an overstatement, don't you think? The TS team explicitly says their goal is to generate readable JS, unlike (for example) Clojure or Scala. Also, the async/await thing isn't an issue if you target the latest ECMAScript version. That's the only really ugly thing, and it's been easily avoidable for over a year.

Readable JS doesn't mean, convert back to the file in the format you used to for editing. That comment could make people throw away the original and end up with machine generated code when going back.

Have you read transpiled TS before? It's sometimes almost identical to the source. It's as close as you can get to just removing the static typing. Variables have the same names, for example.

I used to have a problem where I'd be debugging the JS instead of TS file because visually, they were almost identical.

Re: TypeScript support added to Create React App

#85
post #43

Earlier quoted context omitted.

What sort of errors are you running into, and what project setup are you using? If you're using Create-React-App-TS, that's a separate fork of CRA 1.x that adds TS support, and has _horribly_ restrictive lint rules (many common style practices are treated as _compile_ errors). See https://github.com/wmonk/create-react-app-typescript/issues/... for discussion. (I ran across this while trying to set up a TS project for…

I use TypeScript every day, and I like it way better than JavaScript, but here is an example of a bad error message: http://ss.nican.net/photo_2018-10-22_22-09-58.jpg

Yup, totally agree - that's pretty tough to read.

In that _specific_ example, I think the key part is the "... is not assignable to ServerRoute | ServerRoute[]". It's just giving you all the fields in the type of the object you _are_ returning, and trying to tell you "I can't go from an A to a B". But yes, hard to pick out the key bits of info in there.

Re: TypeScript support added to Create React App

#86

I'd love to use TypeScript, but I've hit walls of errors that are nearly as bad as the old C++ template errors! (Though to be fair, this was a while ago, the compiler may have improved). SO: Any good way to learn TypeScript, particularly the more complicated types?

Quick q, are the "walls of errors" of errors coming from code you wrote yourself or from 3rd party libraries?

I ask because you say that you want to learn the more complicated types, but I'd say it is better to stick to the basic types for your own code.

It seems obvious to me now, but It took me a while to realize: the reason TS type system is so advanced is to be able to accommodate all the crazy JavaScript APIs that are already out there in the real world. New code doesn't need (and most likely should not) use many of those complicated patterns.

This is also why other compile-to-JS languages have an advantage over TS: they don't have the burden of having to express all the craziness that is JS, and will probably be built around a much simpler/cohesive core of ideas.

TS is still an amazing compiler that provides lots of value: many projects other than TS benefit from TS type definitions. But I'd rather use something else if I'm writing an app from scratch. I'm exploring ClojureScript these days.

Re: TypeScript support added to Create React App

#89
post #66

This is awesome. I recently moved from Typescript to plain Javascript for a project and it is quite frustrating. You don't realise what you had till it's gone!

For someone stubborn that refuse to use TS, what are you missing ? Is it the IDE tools or the compiler error messages, or writing type annotations ?

In addition to icholy's points, stronger typing means one traps a whole class of errors at compile/build time, as opposed to runtime.

Re: TypeScript support added to Create React App

#90
post #24

Earlier quoted context omitted.

Funny, cause just using typescript to compile means you get to drop a lot of Babel dependencies / eslint dependencies.

There's still react-scripts-ts [1] which drops the majority of Babel in the CRA pipeline for solely Typescript. Presumably, it will remain active as it is still a useful alternative if you know you are going to want Typescript from day one. (This Babel-based support is perfect for those unsure and looking to experiment, which is great.) [1] https://github.com/wmonk/create-react-app-typescript

I use react-scripts-ts. There's an open issue discussing the future of it now that CRA does it on its own.

https://github.com/wmonk/create-react-app-typescript/issues/...

Post reply on HN