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

Enforce compatibility with exactOptionalPropertyTypes #36345

Closed
wants to merge 1 commit into from

Conversation

NickGerleman
Copy link
Contributor

Summary:
exactOptionalPropertyTypes is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit undefined.

This is not enabled when using --strict, and is stricter than Flow, leading to most of the typings having an | undefined unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent), so this sets the flag in our tsconfig, and updates properties which are not compatible right now.

We can enforce that the convention is followed with a plugin eslint-plugin-redundant-undefined. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule no-redundant-undefined.

Changelog:
[General][Fixed] - Enforce compatibility with exactOptionalPropertyTypes

Differential Revision: D43700862

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 1, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43700862

@@ -281,12 +281,10 @@ export function SectionList_scrollable(Props: {
ref={ref}
ListHeaderComponent={HeaderComponent}
ListFooterComponent={FooterComponent}
// eslint-disable-next-line react/no-unstable-nested-components
// $FlowFixMe[missing-local-annot]
SectionSeparatorComponent={info => (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ⚠️ packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js line 285 – Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “SectionList_scrollable” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true. (react/no-unstable-nested-components)

// $FlowFixMe[missing-local-annot]
SectionSeparatorComponent={info => (
<CustomSeparatorComponent {...info} text="SECTION SEPARATOR" />
)}
// eslint-disable-next-line react/no-unstable-nested-components
// $FlowFixMe[missing-local-annot]
ItemSeparatorComponent={info => (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ⚠️ packages/rn-tester/js/examples/SectionList/SectionList-scrollable.js line 289 – Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “SectionList_scrollable” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true. (react/no-unstable-nested-components)

@analysis-bot
Copy link

analysis-bot commented Mar 1, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,510,869 +0
android hermes armeabi-v7a 7,826,254 +0
android hermes x86 8,989,589 +0
android hermes x86_64 8,845,995 +0
android jsc arm64-v8a 9,137,855 +0
android jsc armeabi-v7a 8,328,832 +0
android jsc x86 9,191,954 +0
android jsc x86_64 9,451,171 +0

Base commit: f4e56fd
Branch: main

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43700862

NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Mar 1, 2023
Summary:
Pull Request resolved: facebook#36345

`exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`.

This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`.

Changelog:
[General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes`

Differential Revision: D43700862

fbshipit-source-id: 2dd18244145bd95935effeb1476a2ab010f2a32e
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43700862

NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Mar 1, 2023
Summary:
Pull Request resolved: facebook#36345

`exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`.

This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`.

Changelog:
[General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes`

Differential Revision: D43700862

fbshipit-source-id: 20dcbdf02dda4c2ab5c0d61b4d3bee16475b7b44
@@ -18,6 +18,7 @@
"strict-export-declare-modifiers": false,
"whitespace": false,
"use-default-type-parameter": false,
"no-redundant-jsdoc": false
"no-redundant-jsdoc": false,
"no-any-union": false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what type do we need this currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two in "globals.d.ts", where at least the websocket one is consistent with the ones TypeScript provides for browser code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could constrain it a little more, but I think it would make a typing error for anything already assuming it is a specific value without checking.

@NickGerleman
Copy link
Contributor Author

NickGerleman commented Mar 4, 2023

I left a separate comment in microsoft/TypeScript#44419 (comment) since this style of mass-redundant-undefined removes signal the app is asking for, by saying explicit undefined is okay by default. We certainly haven't tested that it always works, but the main source of truth @flow strict says we should be allowing them right now. So, suppressing it in TS, like the DT migration did, does bring the two inline in strictness.

We could also instead clean the slate, and effectively undo DefinitelyTyped/DefinitelyTyped@694c663, so that future | undefined would added intentionally as an opt-in.

Also FYI @orta since you seem to have good context on how we should be treating these options 😅.

NickGerleman added a commit to NickGerleman/react-native that referenced this pull request Mar 8, 2023
Summary:
Pull Request resolved: facebook#36345

`exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`.

This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`.

Changelog:
[General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes`

Reviewed By: lunaleaps

Differential Revision: D43700862

fbshipit-source-id: df1b7c99909db3b761fd6dd7498c1cf6c1cfa6fd
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43700862

Summary:
Pull Request resolved: facebook#36345

`exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`.

This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`.

Changelog:
[General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes`

Reviewed By: lunaleaps

Differential Revision: D43700862

fbshipit-source-id: 85dd15b77a0b65304453395034bc52b60694b47b
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D43700862

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 7858a21.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 8, 2023
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Pull Request resolved: facebook#36345

`exactOptionalPropertyTypes` is a TypeScript 4.4+ option set by users which changes behavior of optional properties, to disable accepting explicit `undefined`.

This is not enabled when using `--strict`, and is stricter than Flow, leading to most of the typings having an `| undefined` unique to TypeScript (added with DefinitelyTyped/DefinitelyTyped@694c663).

We have not always followed this (I have myself previously assumed the two are equivalent). We can enforce that the convention is followed with a plugin `eslint-plugin-redundant-undefined`. This forces us to declare that every optional property accepts an explicit undefined (which Flow would allow). Alternatively, if we do not want to support this, we can enable the existing dtslint rule `no-redundant-undefined`.

Changelog:
[General][Fixed] - Enforce compatibility with `exactOptionalPropertyTypes`

Reviewed By: lunaleaps

Differential Revision: D43700862

fbshipit-source-id: 996094762b28918177521a9471d868ba87f0f263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants