News for hackers. Stuff that matters.
Re:Create React App 2.0: Babel 7, Sass, and More by b-nint on Monday October 01, 2018 @10:08PM (#18118304)
I'm disappointed setting up typescript is still such a pain with 2.0.
Re:Create React App 2.0: Babel 7, Sass, and More by danabramov on Monday October 01, 2018 @10:19PM (#18118349)
Sorry. We needed to prioritize to get this release out because it's already been snowballing for about a year.

We actually did have "TypeScript support" on a nice-to-have list for this two week sprint but unfortunately didn't get to it:

https://i.imgur.com/l0CpdZy.png (I promise I'm not making this up :-)

I'm confident we'll ship it by the end of this year though.

Re:Create React App 2.0: Babel 7, Sass, and More by Vinnl on Tuesday October 02, 2018 @03:26AM (#18119453)
> I'm confident we'll ship it by the end of this year though.

Oh wow, that statement is so much more than I'd have expected - there's something to look forward to!

Re:Create React App 2.0: Babel 7, Sass, and More by ggregoire on Monday October 01, 2018 @11:22PM (#18118579)
There is already a pull request and it looks promising!

https://github.com/facebook/create-react-app/pull/4837

Re:Create React App 2.0: Babel 7, Sass, and More by andrethegiant on Monday October 01, 2018 @11:23PM (#18118581)
What is the status of Flow in the JS ecosystem?
Re:Create React App 2.0: Babel 7, Sass, and More by root_axis on Tuesday October 02, 2018 @01:08AM (#18118962)
Flow offers a more sophisticated type system that is designed to express types that correspond with the sort of idioms you see in JavaScript in the wild. TypeScript is simpler and less flexible, but that simplicity can translate into increased productivity since there are less foot-guns and also less bugs. Strange/buggy behavior and odd performances issues are not totally uncommon with Flow whereas TypeScript doesn't seem to suffer from this as much. Since TypeScript is much more popular, IDE support tends to be a lot better out of the box, but the flow-langauge-server gives you all the same IDE-like features (intelligent autocomplete, jump-to-def, module resolution etc).

Personally, I like Flow more, and I also think its easier to integrate into an existing codebase (either as comment annotations or gradually via per-file flow comment header), but at the end of the day, not choosing TypeScript amounts to swimming against the current without much justification.

Re:Create React App 2.0: Babel 7, Sass, and More by WorldMaker on Tuesday October 02, 2018 @01:26PM (#18123734)
> Personally, I like Flow more, and I also think its easier to integrate into an existing codebase (either as comment annotations or gradually via per-file flow comment header)

For several versions now, Typescript also supports type annotations in JS comments and an allowJS mode for mixing TS and JS in the same project, or using only JS and JS comment type annotations.

Re:Create React App 2.0: Babel 7, Sass, and More by paavohtl on Tuesday October 02, 2018 @02:56AM (#18119342)
>Flow offers a more sophisticated type system that is designed to express types that correspond with the sort of idioms you see in JavaScript in the wild. TypeScript is simpler and less flexible, but that simplicity can translate into increased productivity since there are less foot-guns and also less bugs.

Source? That's the primary design principle behind TypeScript too. TypeScript's type system is powerful enough to practically do arbitrary type-level transformation of data structures, and even do some crazy recursive pure functional type level programming.

The only things I'm missing from TypeScript are variadic generics (which can be emulated quite well with TS 3.0) and higher kinded types - and I don't think Flow supports them either.

Re:Create React App 2.0: Babel 7, Sass, and More by root_axis on Tuesday October 02, 2018 @12:24PM (#18123105)
https://flow.org/en/docs/types/utilities/

Most of that can't be achieved out of the box with TypeScript. TypeScript was designed as a language that would bridge the quality of life gap between es5 and more modern languages, Flow was designed exclusively as a type system for annotating standards compliant JS.

Re:Create React App 2.0: Babel 7, Sass, and More by paavohtl on Tuesday October 02, 2018 @02:42PM (#18124444)
Are you aware the TypeScript has mapped types and conditional types[1]? The vast majority of Flow's type utils can be implemented in TypeScript, and many of them are included by default[2]. As far as I can tell all of Flow's utility types are compiler built-ins[3], but TypeScript's built-ins are declared using the type system itself (or are just natural parts of the syntax):

  type Keys<T> = keyof T
  type Values<T> = T[keyof T]
  type Readonly_<T> = Readonly<T>
  type Shape<T> = Partial<T>
  type NonMaybeType<T> = NonNullable<T>

  // Exact<T> cannot be implemented because TS doesn't have exact types as a separate concept,
  // It should be noted that object literals are exact by-default if there's a type annotation
  // Issue: https://github.com/Microsoft/TypeScript/issues/12936

  type Diff<A, B> = Pick<A, Exclude<keyof A, keyof B>>
  // Rest<T> should be equal to Diff, because TS doesn't have exact types

  type ElementType<T, K extends keyof T> = T[K]
  // PropertyType in unnecessary, because T[K] works for everything

  // Note that this is variadic - "Args" is an array of arguments
  type Call<F, Args extends any[]> = F extends (...args: Args) => infer B ? B : never

  // This works for both objects and tuples.
  type ObjMap<T, F> = { [K in keyof T]: Call<F, [T[K]]> }

  // I couldn't figure out how to implement Class<T>, but you can access the type of a class instance with
  // typeof ClassName.prototype 

  // $SuperType and $Subtype are not documented, so I can't try to replicate them.

  // TypeScript doesn't have existential types, but you can emulate them within the type system, or avoid them using e.g "infer"
  // Discussion and encoding https://github.com/Microsoft/TypeScript/issues/14466#issuecomment-338045331

I don't agree with your statement about TypeScript's design. Before ES6 TypeScript _was_ quite different from JS, but for the past 3 or 4 years it has followed modern JS very closely. The flavor of JS it supports is fully compliant with ES2018, and the ONLY feature with codegen impact it has in addition to modern JS and JSX are enums - which compile down to simple object literals.

[1] https://www.typescriptlang.org/docs/handbook/advanced-types.... [2] https://github.com/Microsoft/TypeScript-Handbook/blob/master... [3] https://github.com/facebook/flow/blob/cf03c08109014c4503a392...

Re:Create React App 2.0: Babel 7, Sass, and More by ng12 on Tuesday October 02, 2018 @01:07PM (#18123553)
Not true, most of that can be done with TypeScript. $Values might be the only one missing.
Re:Create React App 2.0: Babel 7, Sass, and More by WorldMaker on Tuesday October 02, 2018 @01:22PM (#18123686)
$Values should be possible with Typescript 3.0+ conditional infer types, presumably something very similar to the built-in ReturnType<T> conditional infer type.

Untested and off the top my head but maybe something like:

    type Values<T> = T extends { [K keyof T]: infer R } ? R : any
Re:Create React App 2.0: Babel 7, Sass, and More by wyze on Tuesday October 02, 2018 @01:34PM (#18123821)
It works, just need to add `in` in-between `K` and `keyof`.
Re:Create React App 2.0: Babel 7, Sass, and More by wyze on Tuesday October 02, 2018 @01:31PM (#18123788)
Looks like $Values can be written as follows in TypeScript:

    type Props = {
      age: number
      name: number
    }

    type Values = Props[keyof Props]
Re:Create React App 2.0: Babel 7, Sass, and More by ng12 on Tuesday October 02, 2018 @11:12AM (#18122405)
Does Flow still run as a separate process? That is a non-starter for me.
Re:Create React App 2.0: Babel 7, Sass, and More by root_axis on Tuesday October 02, 2018 @12:29PM (#18123172)
A separate process from what? The IDE? Why would that be a bad thing?
Re:Create React App 2.0: Babel 7, Sass, and More by ng12 on Tuesday October 02, 2018 @01:04PM (#18123521)
The last time I used Flow it was intended to be used a daemon constantly watching your code. This made it really difficult to use with tools like Webpack which are built for "atomic" operations like tsc.
Re:Create React App 2.0: Babel 7, Sass, and More by ssalka on Tuesday October 02, 2018 @12:11AM (#18118736)
Everyone I know who uses it wishes they had gone with TypeScript. Anecdotal for sure, but I wouldn't be surprised if most Flow users felt this way - TS is winning in basically every way.
Re:Create React App 2.0: Babel 7, Sass, and More by jaaames on Monday October 01, 2018 @11:16PM (#18118561)
Thanks for the release regardless!
Re:Create React App 2.0: Babel 7, Sass, and More by aikah on Tuesday October 02, 2018 @01:44AM (#18119089)
> Sorry. We needed to prioritize to get this release out because it's already been snowballing for about a year.

Why does the project generated by react-native-cli contains some flow syntax by default? this is stupid. Not everybody has a flow plugin for his IDE. And obviously flow type declarations are not valid JavaScript. I understand you want to push your stack onto your users but no need to be that invasive.

Re:Create React App 2.0: Babel 7, Sass, and More by andrewstuart on Tuesday October 02, 2018 @02:29AM (#18119247)
Exactly this. Create React App is awesome except its not TypeScript, and unfortunately the key point of Create Reacte App is that it is opinionated which is its magnificent strength, but it's opinion is not TypeScript as the primary language choice. It's a pity TypeScript isn't the default.

I'd list Create React App as the number one best JavaScript technology of all time, awarded for the massive pain saving it confers. It allows the most fabulous thing in the world, which is to avoid using the JavaScript tooling.

Re:Create React App 2.0: Babel 7, Sass, and More by acemarke on Monday October 01, 2018 @10:46PM (#18118471)
Worth noting that the CRA-TS project (a totally separate repo) is in the process of merging in the changes from CRA 2.0: https://github.com/wmonk/create-react-app-typescript/issues/...
Re:Create React App 2.0: Babel 7, Sass, and More by jaaames on Monday October 01, 2018 @11:14PM (#18118553)
Yeah these guys follow quickly, I've used this multi times and can highly recommend.
Re:Create React App 2.0: Babel 7, Sass, and More by arenaninja on Monday October 01, 2018 @10:13PM (#18118323)
Really? If anything the move to babel 7 makes it easy, use babel-loader for .tsx?$ files with @babel/preset-typescript

I've setup about 4 projects over the past year, if you feel like you need help feel free to email me any particular pain points you have and I'll try to get you through them, email in profile (not a react contributor, just frequent react/typescript user on financial applications)

Re:Create React App 2.0: Babel 7, Sass, and More by acemarke on Monday October 01, 2018 @10:47PM (#18118478)
I'd actually love to see a good blog post that details the process of, say, upgrading from Babel 6 to Babel 7 for a non-CRA app, and then adding in some form of TS support on top of that. (I've got a couple apps that I'd like to try doing that with myself in the not too distant future.)
Re:Create React App 2.0: Babel 7, Sass, and More by sbr464 on Tuesday October 02, 2018 @01:27AM (#18119030)
I don’t have a post but I took a half hour the other day and did it, it was basically:

Add typescript, babel typescript, add the plugin in babelrc, and update the Babel cli build command in package.json to look for ts file extensions.

That enabled me to start incrementally adding typescript into an existing node.js codebase, I was surprised how easy it was.

Re:Create React App 2.0: Babel 7, Sass, and More by sbr464 on Tuesday October 02, 2018 @03:46AM (#18119530)
Here were the changes to get typescript working with an existing node.js codebase (babel 7)

package.json (scripts)

  BABEL_ENV=development babel -d build/ src/ --extensions \".ts,.tsx,.js\" --quiet --source-maps inline
package.json (add property)

  "type-check": "tsc",
package.json (dev depenencies)

  @babel/preset-typescript, typescript
babelrc (add with env)

  presets: ["@babel/typescript"]
tsconfig (example)

  {
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "declaration": true,
    "outDir": "build",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}
Re:Create React App 2.0: Babel 7, Sass, and More by ianschmitz on Tuesday October 02, 2018 @12:51AM (#18118891)
Check out https://github.com/strothj/react-app-rewire-typescript-babel... for an example I helped get going. It was fairly straight forward!
Re:Create React App 2.0: Babel 7, Sass, and More by acemarke on Tuesday October 02, 2018 @01:23AM (#18119020)
Thanks, appreciate it!
Re:Create React App 2.0: Babel 7, Sass, and More by streptomycin on Monday October 01, 2018 @11:27PM (#18118600)
They are independent, so you could read two blog posts, one for Babel 7 https://babeljs.io/docs/en/v7-migration and one for TS https://blogs.msdn.microsoft.com/typescript/2018/08/27/types...
Re:Create React App 2.0: Babel 7, Sass, and More by Vinnl on Tuesday October 02, 2018 @03:28AM (#18119459)
Then you'd still need to explicitly do type checking, which is the primary advantage of TypeScript. I guess my IDE can do that, but then I'd still need to add an extra step to my CI server, etc.

Native TypeScript support will be a huge improvement.

Re:Create React App 2.0: Babel 7, Sass, and More by daok on Monday October 01, 2018 @10:30PM (#18118402)
+1 for TypeScript. The current existing ports of CRA for TypeScript are always behind.
Re:Create React App 2.0: Babel 7, Sass, and More by pmalynin on Monday October 01, 2018 @10:11PM (#18118316)
Use ParcelJS and Typescript. Couldn't be easier.
Re:Create React App 2.0: Babel 7, Sass, and More by PudgePacket on Monday October 01, 2018 @10:33PM (#18118413)
From memory one of the issues on github says it's coming in 2.1. It just wasn't determined to be a "blocker" for 2.0.
Re:Create React App 2.0: Babel 7, Sass, and More by sephware on Monday October 01, 2018 @10:36PM (#18118430)
TypeScript is fantastic for its IDE support and instant feedback but I'm waiting for the day it's built into CRA as a first class citizen. Sounds like that day will be soon though maybe even this year.
Re:Create React App 2.0: Babel 7, Sass, and More by fermentation on Monday October 01, 2018 @10:09PM (#18118308)
Why would facebook be interested in making it easy to use a technology that they directly compete against?
Re:Create React App 2.0: Babel 7, Sass, and More by sophiebits on Monday October 01, 2018 @10:16PM (#18118338)
Speaking for the React team, we have little reason to suggest people use Flow over TypeScript.

I haven’t personally followed the status of TS in CRA closely, but I know it’s a popular request among our users so I would love for us to make it easy.

Re:Create React App 2.0: Babel 7, Sass, and More by fermentation on Monday October 01, 2018 @10:20PM (#18118359)
That's certainly comforting to hear, then.

Sometimes it gets confusing connecting the negative news of these large companies to their cool open source projects.

Re:Create React App 2.0: Babel 7, Sass, and More by holman on Monday October 01, 2018 @10:15PM (#18118333)
Eh, the React team in particular is pretty even-handed when it comes to what goes into CRA. This release, for example, adds support for Apollo, which goes head-to-head with Relay.

I’ve been pretty happy with the team’s thoughtful approach to adding a dependency or not.