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

How to force to use @types/react-native instead of built-in STALED dts files #37670

Closed
xsjcTony opened this issue Jun 2, 2023 · 1 comment
Closed
Labels
Resolution: Answered When the issue is resolved with a simple answer

Comments

@xsjcTony
Copy link
Contributor

xsjcTony commented Jun 2, 2023

Description

TL;DR: Is there a way to force TypeScript to use @types/react-native instead of built-in staled node_modules/react-native/types files?

Built-in types do NOT align with the current react-native version, e.g. #36441, it doesn't make sense to use staled types. I know it will be fixed in the near future, but still it's not good, so I'd like to use up-to-date @types/react-native instead.


Refer to #36441, I'm trying to work around this one. I found out that in the DefinitelyTyped package, this has been updated by DefinitelyTyped/DefinitelyTyped#65144, which means, if I delete node_modules/react-native/types in my local, everything just worked, there's no more error complaining about the invalid autoComplete prop value (I'm using new-password in this case).

That's definitely not the ideal solution, since in another environment, like the auto-building process, this won't be performed and tsc will complain about ti again.

I do want to use the built-in version, but somehow it's not even aligned with the latest version of the app.

Any solution I can use? Adding "types": ["react-native"] in tsconfig.json doesn't help.

React Native Version

~0.71.8

Output of npx react-native info

System:
OS: Windows 10 10.0.19045
CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
Memory: 25.28 GB / 63.84 GB
Binaries:
Node: 18.16.0 - C:\NodeJS\node.EXE
Yarn: 1.22.19 - C:\NodeJS\yarn.CMD
npm: 9.6.7 - C:\NodeJS\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowAllTrustedApps: Disabled
IDEs:
Android Studio: AI-222.4459.24.2221.9971841
Visual Studio: Not Found
Languages:
Java: 17.0.1 - C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
npmPackages:
@react-native-community/cli: Not Found
react: ~18.2.0 => 18.2.0
react-native: ~0.71.8 => 0.71.8
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

essential package.json:

{
 "dependencies": {
    "react": "~18.2.0",
    "react-native": "~0.71.8"
  },
  "devDependencies": {
    "@types/react": "~18.2.8",
    "@types/react-native": "~0.71.7",
    "typescript": "^5.1.3"
  }
}

By default it will error (see code snippet below)
Deleting node_modules/react-native/types folder, it works, because types in @types/react-native is correct

Snack, code example, screenshot, or link to a repository

import { TextInput } from 'react-native'
import type { JSX } from 'react'

const App = (): JSX.Element => (
    <TextInput autoComplete="new-password" />
    //                       ^^^^^^^^^^^^
    // TS complaining about this for `built-in types`
    // but working as expected with `@types/react-native`
)
@cortinico
Copy link
Contributor

Built-in types do NOT align with the current react-native version, e.g. #36441, it doesn't make sense to use staled types. I know it will be fixed in the near future, but still it's not good, so I'd like to use up-to-date @types/react-native instead.

If types are wrong, we should just fix them and align them. You should not rely on DefinitelyTyped/DefinitelyTyped anymore as we might eventually fade them away.

If you wish this commit 94356e1 backported to 0.71, you should just ask for it in the release working group: reactwg/react-native-releases#69

Closing as this is a question effectively.

@cortinico cortinico added Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests

2 participants