Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge the syntax gap between _Flow_ and _TypeScript_ #8989

Open
15 of 16 tasks
Conaclos opened this issue Jan 24, 2023 · 6 comments
Open
15 of 16 tasks

Bridge the syntax gap between _Flow_ and _TypeScript_ #8989

Conaclos opened this issue Jan 24, 2023 · 6 comments

Comments

@Conaclos
Copy link

Conaclos commented Jan 24, 2023

Proposal

The goal of this proposal is to improve interoperability between Flow and TypeScript.

  • Allow export declare as an alias of declare export
  • Add as const type assertions
  • Add type guards, e.g. const isNumber = (x: unknown): x is number => typeof x === "number"
  • Add unknown type as an alias of mixed
  • Add undefined type as an alias of void
  • Add readonly as an alias of + in object type and interface. e.g. type Person = { readonly name: string }.
  • Add in, out as aliases of - and + for type parameter variance
  • Add extends as an alias of : for type parameter bounds. e.g. function f<A extends string>(a:A){}.
  • Add never type as an alias of empty
  • Add type guards (x: unknown) => x is X
  • Add as type assertion as an alias of (:)
  • Add keyof T as an alias of $Keys<T>
  • Add readonly arrays readonly string[]
  • Add readonly tuples readonly [string, number]
  • Add Readonly, ReadonlyArray, ReadonlySet, ReadonlyMap, Record<K, V> as aliases of $ReadOnly, $ReadOnlyArray, $ReadOnlySet, $ReadOnlyMap, { [key: K]: V }
  • Add Partial, Required utility types

Use case

I would like to use Flow. However, it is hard to give up all TypeScript tooling.
More interoperability could help to use Flow.

@gkz
Copy link
Member

gkz commented Jan 24, 2023

We already have symbol as a type. As of the next version, we parse and error (with a quickfix to the Flow version) everything you've mentioned above other than type guards and the utility type aliases.

@Conaclos
Copy link
Author

We already have symbol as a type

I updated the issue :)

As of the next version, we parse and error (with a quickfix to the Flow version) everything you've mentioned above other than type guards and the utility type aliases.

Thanks for the info :)

The main goal of this issue is improving compatibility between Flow and TypeScript.
I love the strictness of Flow.
I think there is no value to defend a distinct syntax.
Flow evolved in parallel of TypeScript.
However, TypeScript is now largely spread.
This makes hard to defend a distinct syntax for types like unknown, ...

@gkz
Copy link
Member

gkz commented Jan 24, 2023

The first step to potentially changing out syntax is parsing it, and then updating all tooling (Prettier, ESLint, etc.) to handle these new AST nodes. That process takes a while (but by parsing and erroring, we're starting it). Once that is done, all that would be required is for Flow to make the change, and we will have discussions on a case by case basis - it's something we're thinking about for sure

@Conaclos
Copy link
Author

Conaclos commented Jan 24, 2023

Thanks for your input :)

@gkz
Copy link
Member

gkz commented Mar 17, 2023

We have Partial and Required now: https://medium.com/flow-type/announcing-partial-required-flow-utility-types-catch-annotations-3a32f0bf2a20

@matclayton
Copy link

Firstly thank you for flow! It’s been an amazing tool for us at mixcloud, especially when combine with relay.

However unfortunately we’re fighting an uphill battle compared to the typescript 3rd party library support. I wonder if there is any appetite for allowing flow to ingest typescript types for 3rd party libraries or using flow-gen to automate bridging the gap somehow? Allowing us to benefit from flows speed/correctness and the typescript ecosystem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants