-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[TypeScript] [Stylesheet] TS2322 error thrown when transform
property is used in a style object returned from a function
#41869
Comments
Reproducer added |
@hieucd04 I can't reproduce the error, using the project-specified version of TypeScript installed to |
@huntie Can you try it one more time using cmd More info:
|
If I add a synthetic error to the file, Running It looks like this causes a type error then on the default config, but not the tsconfig we ship. Differences compared to the default include things like |
@NickGerleman: I looked into the {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Native",
"compilerOptions": {
"target": "esnext",
"module": "es2015",
"types": ["react-native", "jest"],
"lib": [
"es2019",
"es2020.bigint",
"es2020.date",
"es2020.number",
"es2020.promise",
"es2020.string",
"es2020.symbol.wellknown",
"es2021.promise",
"es2021.string",
"es2021.weakref",
"es2022.array",
"es2022.object",
"es2022.string"
],
"allowJs": true,
"jsx": "react-native",
"noEmit": true,
"isolatedModules": true,
"strict": true,
"moduleResolution": "bundler",
"customConditions": ["react-native"],
"allowImportingTsExtensions": true,
"allowArbitraryExtensions": true,
"resolveJsonModule": true,
"resolvePackageJsonImports": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
// Causes issues with package.json "exports"
"forceConsistentCasingInFileNames": false
},
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}
The reason running So now we understand the problem, hopefully, I need confirmation from React Native team to derive a solution of my own:
|
I don’t think we’ve been forced to think about whether the strict mode option is a requirement. Ideally I think it wouldn’t be, since it is slightly opinionated, and not all existing RN code is compatible with it (but subjectively, you really should be using it). I would recommend sticking to using the template config though. The tsconfig we ship is tuned to support the features of React Native, and there may be cases in the future where the default settings do not work (e.g. we have considered using the package.json exports field before, which requires different resolution settings than the TypeScript default). |
I think the real problem here is not with aforementioned PR #38348 - which I consider beneficial. TypeScript here just infers a wider type than we would like it to. To fix this all you need to do is: diff --git a/ReproducerApp/the-bug-is-here.ts b/ReproducerApp/the-bug-is-here.ts
index 9eea77e..cddd792 100644
--- a/ReproducerApp/the-bug-is-here.ts
+++ b/ReproducerApp/the-bug-is-here.ts
@@ -9,5 +9,5 @@ const styleCreator: StyleCreator = function () // Doesn't work. TS2322 error is
{
return {
transform: [{translateX: 15}, {rotateX: "45deg"}]
- };
+ } as ViewStyle; // or even better TransformsStyle
}; to make it go away. |
I learned from @eps1lon that DefinitelyTyped itself checks with I think if DT only checks against |
Steps to reproduce
reproducer
yarn reproduce
Actual Result: Error is thrown
Expected Result: No error is thrown
More info:
react-native: 0.72.7
will fix this issueReact Native Version
0.73.0
Affected Platforms
Build - Windows
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/hieucd04/reproducer-react-native
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: