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

Flow: use implicit exact object types #1961

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

mrtnzlml
Copy link
Member

@mrtnzlml mrtnzlml commented Mar 11, 2021

Flow standard is now to use { } for strict objects and { key: value, ... } for open objects, see: facebook/relay@6fa0b0d and facebook/react-native@00cfb0f

This change should be without any problems as longs as users of our NPM libraries are using Flow with exact_by_default=true (which is now pretty standard I'd say).

Here is how object types behave before this change:

type A = { x: number }; // already "exact" type but disallowed because it would be confusing to mix different syntaxes
type B = { x: number, ... }; // this is inexact
type C = {| x: number |}; // this is explicitly exact and the only allowed way how to describe type "exactness"

Here is how object types behave after this change:

type A = { x: number }; // this is the only allowed syntax for "exact" type
type B = { x: number, ... }; // this is still inexact
type C = {| x: number |}; // this is also exact but no longer allowed (so it's not confusing)

Some related (non-blocking) issues:

TODO:

@mrtnzlml
Copy link
Member Author

mrtnzlml commented Mar 11, 2021

Draft only for now: still investigating what gets broken, what are the consequences, and how to make sure we keep the codebase unified.

@mrtnzlml mrtnzlml added the help wanted Extra attention is needed label Mar 11, 2021
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 75951e2 to e1ac84a Compare March 15, 2021 16:00
@vercel vercel bot temporarily deployed to Preview – universe-example-relay March 15, 2021 16:00 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website March 15, 2021 16:00 Inactive
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from e1ac84a to 75ca687 Compare March 23, 2021 19:06
@vercel vercel bot temporarily deployed to Preview – universe-example-relay March 23, 2021 19:06 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website March 23, 2021 19:06 Inactive
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 75ca687 to f02b28f Compare April 4, 2021 22:50
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 4, 2021 22:50 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 4, 2021 22:50 Inactive
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from f02b28f to 003edce Compare April 5, 2021 23:16
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 5, 2021 23:16 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 5, 2021 23:16 Inactive
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 003edce to d4e0634 Compare April 5, 2021 23:54
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 5, 2021 23:54 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 5, 2021 23:54 Inactive
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from d4e0634 to 2c6f101 Compare April 6, 2021 00:04
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 6, 2021 00:04 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 6, 2021 00:04 Inactive
@mrtnzlml mrtnzlml removed the help wanted Extra attention is needed label Apr 6, 2021
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 2c6f101 to d67e0eb Compare April 6, 2021 00:16
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 6, 2021 00:16 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 6, 2021 00:16 Inactive
@mrtnzlml
Copy link
Member Author

mrtnzlml commented Apr 6, 2021

@adeira/devs could you please have a look at this PR draft and share your opinion/concerns? Thanks! 😎

@michalsanger
Copy link
Contributor

I'd say let’s do this.

think about backward compatibility

What exactly do you mean by this? BC within the Universe monorepo? Can it be achieved and do we even need it?

what about exported NPM libs with these new types?

Could a new major release be the solution?

@mrtnzlml
Copy link
Member Author

mrtnzlml commented Apr 6, 2021

think about backward compatibility

What exactly do you mean by this? BC within the Universe monorepo? Can it be achieved and do we even need it?

For example, how does it behave when we publish an NPM package with this new setup and users of our package are using the old setup? I would like to know the answer before giving this PR for a proper review.

I guess both of these TODOs are the same and I had the question twice without noticing. 😬

what about exported NPM libs with these new types?

Could a new major release be the solution?

It can be a solution, yes. I'd like to check first if it's necessary though. Also, Flow usage is quite low so we probably can cut some corners.

@michalsanger
Copy link
Contributor

If I understand this correctly, when you are using the old syntax and start mixing it with the new one, you are basically using weaker types. You don't get any Flow errors. In this meaning it's backward compatible, but from DX perspective I would appreciate a big info in changelog. Major version could be that big info, on the other hand do you see any libs with Flow types doing this?

@mrtnzlml
Copy link
Member Author

mrtnzlml commented Apr 6, 2021

If I understand this correctly, when you are using the old syntax and start mixing it with the new one, you are basically using weaker types. You don't get any Flow errors. In this meaning it's backward compatible, but from DX perspective I would appreciate a big info in changelog. Major version could be that big info, on the other hand do you see any libs with Flow types doing this?

Edit: yeah, that's pretty much correct (I missed the "when you are using the old syntax" part). If you are still using exact_by_default=false then you are out of luck.

I believe this is not correct. There are many changes in this PR but they are mostly syntactical - no big changes in terms of behavior. That's thanks to the fact that we are using "exact by default" behavior for a long time. Here is how it is now:

export type A = { x: number }; // this is already "exact" type but disallowed because it would be confusing to mix different syntaxes
export type B = { x: number, ... }; // this is inexact
export type C = {| x: number |}; // this is explicitly exact and the only allowed way how to describe type "exactness"

Here is what this PR changes:

export type A = { x: number }; // this is the only allowed syntax for "exact" type
export type B = { x: number, ... }; // this is still inexact
export type C = {| x: number |}; // this is also exact but no longer allowed (so it's not confusing)

That's why I believe that changing {| x: number |} to { x: number } in our NPM libraries should be fine (with no BC break and no change in the type soundness) as long as you use exact_by_default=true. This feature was rolled out as follows:

  • v0.101.0 (10 Jun 2019) new implicit-inexact-object lint
  • v0.105.0 (9 Aug 2019) new exact_by_default option in flowconfig
  • we started using exact_by_default=true 9 Nov 2019, see: a9037e6
  • v0.112.0 (12 Nov 2019) new ambiguous-object-type lint
  • v0.148.0 is the latest Flow version

This timeline makes me think that it should be fine to proceed (6 Apr 2021). Please note though that I didn't actually try it yet so I might be wrong.

@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 5b65810 to b6647ed Compare April 7, 2021 14:01
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 7, 2021 14:01 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 7, 2021 14:01 Inactive
mrtnzlml added a commit that referenced this pull request Apr 7, 2021
This change turns `NEXT_VERSION_ERROR` rules into `ERROR` rules and updates minimum required Eslint version to `>=7.23.0`. The plan is to coordinate this change with the release of implicit exact Flow types (#1961) which is the main breaking change.
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from b6647ed to 45c7d46 Compare April 8, 2021 14:28
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 8, 2021 14:28 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 8, 2021 14:28 Inactive
Flow standard is now to use `{ }` for strict objects and `{ key: value, ... }` for open objects, see: facebook/relay@6fa0b0d and facebook/react-native@00cfb0f

This change should be without any problems as longs as users of our NPM libraries are using Flow with `exact_by_default=true` (which is now pretty standard I'd say).

Here is how object types behave before this change:

```
type A = { x: number }; // already "exact" type but disallowed because it would be confusing to mix different syntaxes
type B = { x: number, ... }; // this is inexact
type C = {| x: number |}; // this is explicitly exact and the only allowed way how to describe type "exactness"
```

Here is how object types behave _after_ this change:

```
type A = { x: number }; // this is the only allowed syntax for "exact" type
type B = { x: number, ... }; // this is still inexact
type C = {| x: number |}; // this is also exact but no longer allowed (so it's not confusing)
```

Some related (non-blocking) issues:

- gajus/eslint-plugin-flowtype#467
- facebook/flow#8612
@mrtnzlml mrtnzlml force-pushed the flow_implicit_exact_by_default_evolution branch from 45c7d46 to ef6d4ff Compare April 8, 2021 14:51
@vercel vercel bot temporarily deployed to Preview – universe-example-relay April 8, 2021 14:51 Inactive
@vercel vercel bot temporarily deployed to Preview – universe-sx-tailwind-website April 8, 2021 14:51 Inactive
@kodiakhq kodiakhq bot merged commit 5f0c905 into master Apr 8, 2021
@kodiakhq kodiakhq bot deleted the flow_implicit_exact_by_default_evolution branch April 8, 2021 15:02
mrtnzlml added a commit that referenced this pull request Apr 8, 2021
This change turns `NEXT_VERSION_ERROR` rules into `ERROR` rules and updates minimum required Eslint version to `>=7.23.0`. The plan is to coordinate this change with the release of implicit exact Flow types (#1961) which is the main breaking change.
kodiakhq bot pushed a commit that referenced this pull request Apr 8, 2021
This change turns `NEXT_VERSION_ERROR` rules into `ERROR` rules and updates minimum required Eslint version to `>=7.23.0`. The plan is to coordinate this change with the release of implicit exact Flow types (#1961) which is the main breaking change.
adeira-github-bot pushed a commit to adeira/eslint-config-adeira that referenced this pull request Apr 8, 2021
This change turns `NEXT_VERSION_ERROR` rules into `ERROR` rules and updates minimum required Eslint version to `>=7.23.0`. The plan is to coordinate this change with the release of implicit exact Flow types (adeira/universe#1961) which is the main breaking change.

adeira-source-id: 2bca35f7709df284c10938b7f19fbf1414a1b2f7
@mrtnzlml
Copy link
Member Author

OSS versions of FBT and Recoil are now also getting this change, see: https://github.com/search?q=%22fb-www%2Fflow-exact-by-default-object-types%22&type=commits (fbt, recoil)

mrtnzlml added a commit that referenced this pull request Apr 21, 2021
Followup after #1961 (some special types were not converted yet)
kodiakhq bot pushed a commit that referenced this pull request Apr 22, 2021
Followup after #1961 (some special types were not converted yet)
adeira-github-bot pushed a commit to adeira/babel-preset-adeira that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/eslint-plugin-sx that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/relay-example that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/relay that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/sx-tailwind-website that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/sx that referenced this pull request Apr 22, 2021
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
adeira-github-bot pushed a commit to adeira/babel-plugin-transform-sx-tailwind that referenced this pull request Apr 30, 2022
Followup after adeira/universe#1961 (some special types were not converted yet)

adeira-source-id: b2d1f91ed135188859ab31d6c6ee48cd102919a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants