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

Missing TypeScript types for userSelect style property on Text component - type error: 'userSelect' does not exist in type #39015

Closed
jobpaardekooper opened this issue Aug 15, 2023 · 8 comments
Assignees
Labels
Bug Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Typescript

Comments

@jobpaardekooper
Copy link

jobpaardekooper commented Aug 15, 2023

Description

When setting the userSelect property inside the style property of a Text component you get a Typescript error. For example:

<Text style={{ userSelect: 'all' }} >example</Text>

Gives the following type error:

Type '{ userSelect: string; }' is not assignable to type 'StyleProp<TextStyle>'.
      Object literal may only specify known properties, and 'userSelect' does not exist in type 'TextStyle | RecursiveArray<Falsy | TextStyle | RegisteredStyle<TextStyle>>'.

React Native Version

0.72.4

Output of npx react-native info

System:
OS: macOS 13.4
CPU: (10) arm64 Apple M1 Pro
Memory: 442.78 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 16.13.0
path: ~/.nvm/versions/node/v16.13.0/bin/node
Yarn:
version: 1.22.15
path: ~/.nvm/versions/node/v16.13.0/bin/yarn
npm:
version: 9.8.1
path: ~/Developer/transcribe/rn-app/node_modules/.bin/npm
Watchman:
version: 2023.06.12.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.12.1
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 22.4
- iOS 16.4
- macOS 13.3
- tvOS 16.4
- watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8609683
Xcode:
version: 14.3/14E222b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.1
path: /usr/bin/javac
Ruby:
version: 3.2.2
path: /Users/jobpaardekooper/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.4
wanted: ^0.72.4
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Steps to reproduce

Create a Text component in a Typescript file as follows:

<Text style={{ userSelect: 'all' }} >example</Text>

Snack, screenshot, or link to a repository

https://github.com/jobpaardekooper/rn-userSelect-example

@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Aug 15, 2023
@cortinico
Copy link
Contributor

We do have a sample in React Native that tests exactly that:

{
title: 'Selectable Text',
render: function (): React.Node {
return (
<View>
<Text style={{userSelect: 'auto'}}>Text element is selectable</Text>
</View>
);
},
},

Can you share a reproducer as requested?

@github-actions github-actions bot removed the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Aug 15, 2023
@jobpaardekooper
Copy link
Author

I have created a repo that reproduces the issue but it is really nothing special. All I did was add a Text component like in my original description of the issue.

To be clear, the Text component is selectable and is working as it should. It just gives a type error in Typescript. For example when I have the project open in VSCode is see this:

Screenshot 2023-08-15 at 13 51 22

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 15, 2023
@cortinico cortinico changed the title userSelect style property on Text component type error: 'userSelect' does not exist in type Missing TypeScript types for userSelect style property on Text component - type error: 'userSelect' does not exist in type Aug 15, 2023
@cortinico cortinico added Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Bug Typescript and removed Needs: Triage 🔍 Needs: Attention Issues where the author has responded to feedback. labels Aug 15, 2023
@cortinico
Copy link
Contributor

Oh I see. That's because the TypeScript types haven't been updated.
This should be an easy fix so I marked it as "Good first issue" if someone wants to pick it up

@MjMoshiri
Copy link
Contributor

Hi, I would like to work on this if it's possible

@cortinico
Copy link
Contributor

Hi, I would like to work on this if it's possible

I've assigned it to you 👍

@MjMoshiri
Copy link
Contributor

Hi again, the 1 liner change is ready :D.

@Stunner05
Copy link

Hi, I would like to work on this if it's possible

Can i assist you on this

@MjMoshiri
Copy link
Contributor

Hi, I would like to work on this if it's possible

Can i assist you on this

Hi, sure. If you think something is missing apart from the change I made in the pull request above. Please do 🙏. But I think the intended change is done. merge request already has an approval.

facebook-github-bot pushed a commit that referenced this issue Aug 21, 2023
Summary:
This PR addresses the missing userSelect style support in the TypeScript definitions. While support for userSelect was introduced in commit [fc42d5b](fc42d5b), the associated TypeScript definitions were overlooked. This oversight led to issue #39015. This PR rectifies that by updating the type definitions accordingly.

## Changelog:

[GENERAL] [FIXED] - Updated TypeScript definitions to include userSelect style support. Refer to commit [2e4d8b6](2e4d8b6) for the specific changes.

Pull Request resolved: #39024

Reviewed By: rozele

Differential Revision: D48412051

Pulled By: NickGerleman

fbshipit-source-id: 425fc011af9052c8c4bde98e8524b7784493c546
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Typescript
Projects
None yet
Development

No branches or pull requests

4 participants