react-native: Ensure elements narrowed by isValidElement are valid props#64840
Conversation
|
@eps1lon Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 64840,
"author": "eps1lon",
"headCommitOid": "22c80346eb918a2ad9499f94752f4ac13abc35b0",
"mergeBaseOid": "f296fa25fe4a69f9ca9217a8cd0a7b1474b9b09b",
"lastPushDate": "2023-03-21T17:36:12.000Z",
"lastActivityDate": "2023-03-24T13:45:50.000Z",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "react-native",
"kind": "edit",
"files": [
{
"path": "types/react-native/Libraries/Lists/FlatList.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/Libraries/Lists/SectionList.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/Libraries/Lists/VirtualizedList.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/test/index.tsx",
"kind": "test"
},
{
"path": "types/react-native/v0.63/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.64/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.65/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.66/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.67/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.68/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.69/index.d.ts",
"kind": "definition"
},
{
"path": "types/react-native/v0.70/index.d.ts",
"kind": "definition"
}
],
"owners": [
"alloy",
"huhuanming",
"iRoachie",
"timwangdev",
"kamal",
"alexdunne",
"swissmanu",
"bm-software",
"mvdam",
"esemesek",
"mrnickel",
"souvik-ghosh",
"nossbigg",
"saranshkataria",
"tykus160",
"jakebloom",
"ceyhun",
"mcmar",
"theohdv",
"romain-faust",
"bebebebebe",
"Naturalclar",
"chinesedfan",
"vtolochk",
"SychevSP",
"sasurau4",
"256hz",
"doumart",
"drmas",
"jeremybarbet",
"ds300",
"natsathorn",
"connectdotz",
"alexeymolchan",
"alexbrazier",
"kuasha420",
"phvillegas",
"eps1lon",
"ZihanChen-MSFT",
"kelset",
"MateWW",
"lunaleaps",
"saadnajmi"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [],
"mainBotCommentID": 1479018389,
"ciResult": "pass"
} |
|
🔔 @alloy @huhuanming @iRoachie @timwangdev @kamal @alexdunne @swissmanu @bm-software @mvdam @Esemesek @mrnickel @souvik-ghosh @nossbigg @saranshkataria @tykus160 @jakebloom @ceyhun @mcmar @theohdv @romain-faust @bebebebebe @Naturalclar @chinesedfan @vtolochk @SychevSP @sasurau4 @256hz @doumart @drmas @jeremybarbet @ds300 @natsathorn @connectdotz @alexeymolchan @alexbrazier @kuasha420 @phvillegas @ZihanChen-MSFT @kelset @MateWW @lunaleaps @Saadnajmi — please review this PR in the next few days. Be sure to explicitly select |
| const { ListEmptyComponent } = this.props; | ||
| const listEmptyComponent: JSX.Element | null | undefined = React.isValidElement(ListEmptyComponent) | ||
| ? ListEmptyComponent | ||
| : ListEmptyComponent && <ListEmptyComponent />; |
There was a problem hiding this comment.
ListEmptyComponent is not narrowed to ReactElement<unknown> if a union member is ReactElement<any>. But with the change in this PR the full type is ReactElement<unknown> | ... so isValidElement does narrow it again.
|
cc @lunaleaps |
|
Merging since this has the smallest blast radius as far as I can tell. |
Works around a TypeScript bug introduced between 5.0 Beta and RC that doesn't get attention. To unblock the ecosystem while keeping the blast radius minimal, I'll change the RN types.
This probably doesn't fix all problems caused by TS 5.0 but it fixes the ones I encountered.
We should default the props of
React.ReactElementtounknownanyway which would at least call out explicit breakage when props acceptReact.ReactElement<any>. But that has considerable larger blast-radius so for now libraries have to fix these issues on the spot.