Re:Convert React JavaScript Code to TypeScript with Proper T...
by ggregoire on Tuesday January 16, 2018 @12:35PM
(#16160042)
React is built with Flow. Since Flow and TS achieve the same thing, I'm not sure a React-like library based on TS would bring anything new.
[ Parent
| on HN ]
Re:Convert React JavaScript Code to TypeScript with Proper T...
by ralmidani on Tuesday January 16, 2018 @12:38PM
(#16160075)
I have looked at Flow. I have to admit, I am biased toward good-looking code. Unless you use something like LightScript[0], Flow's syntax is not as clean or straightforward as that of TS.
Edit: I just took another look. I thought parameters had to be annotated via block comments (that's how you have to do it if using CoffeeScript 2). I was wrong.
Re:Convert React JavaScript Code to TypeScript with Proper T...
by ggregoire on Tuesday January 16, 2018 @12:53PM
(#16160241)
The following example written in TS works in Flow too:
type MyComponentProps = {
prop1: string;
prop2?: number;
}
type MyComponentState = {
foo: number;
bar: string;
baz: number;
}
class MyComponent extends Component<MyComponentProps, MyComponentState> {
Same syntax.Also, not sure how this could be more straightforward.
Re:Convert React JavaScript Code to TypeScript with Proper T...
by ralmidani on Tuesday January 16, 2018 @01:00PM
(#16160321)
Thank you. I edited my comment after looking at the Flow website. My incorrect understanding came from seeing the atrocious "block comment Flow annotations" in CoffeeScript 2 (an otherwise adorable language) and thinking that was how you had to specify parameter types with Flow.