Commit 1ea269f
fix: [TypeScript] Allow to pass empty string as style (#43404)
Summary:
```tsx
import {Text} from 'react-native'
interface Props {
foregroundColor?: string | undefined | null
}
function Test({foregroundColor}: Props){
return <Text style=[styles.icon, foregroundColor && { color: foregroundColor }] />
// ^^^ Error: Type "" is not assignable to type TextStyle | Falsy | RegisteredStyle<TextStyle> | RecursiveArray<TextStyle...
}
```
## Changelog:
[GENERAL] [ADDED] - [TypeScript] Allow to pass empty string as style
Pull Request resolved: #43404
Test Plan:
Change `Falsy` type locally and test it on the next code
```tsx
const styles = StyleSheet.create({
text: {
color: 'red',
},
});
export const a = <Text style={[styles.text, null, '', undefined, false]} />;
```
Reviewed By: rshest
Differential Revision: D54744517
Pulled By: javache
fbshipit-source-id: c5b934616cc0501c2b6a7907e6be522187a2cc201 parent 8089146 commit 1ea269f
2 files changed
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
| |||
436 | 438 | | |
437 | 439 | | |
438 | 440 | | |
439 | | - | |
| 441 | + | |
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
443 | 445 | | |
444 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
445 | 453 | | |
446 | 454 | | |
447 | 455 | | |
| |||
0 commit comments