Skip to content

fix: [TypeScript] Allow to pass empty string as style#43404

Closed
retyui wants to merge 1 commit intofacebook:mainfrom
retyui:fix/retyui/ts-update-StyleProp
Closed

fix: [TypeScript] Allow to pass empty string as style#43404
retyui wants to merge 1 commit intofacebook:mainfrom
retyui:fix/retyui/ts-update-StyleProp

Conversation

@retyui
Copy link
Copy Markdown
Contributor

@retyui retyui commented Mar 10, 2024

Summary:

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

Test Plan:

Change Falsy type locally and test it on the next code

const styles = StyleSheet.create({
  text: {
    color: 'red',
  },
});
export const a = <Text style={[styles.text, null, '', undefined, false]} />;

@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: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Mar 10, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 11, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@javache merged this pull request in 1ea269f.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants