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 Class "File" in react-native #38061

Closed
trashcoder opened this issue Jun 26, 2023 · 11 comments
Closed

Missing Class "File" in react-native #38061

trashcoder opened this issue Jun 26, 2023 · 11 comments
Labels
Needs: Attention Issues where the author has responded to feedback.

Comments

@trashcoder
Copy link
Contributor

Description

In react-native there is no class "File". It would make Uploads easier with appwrite because their storage.createFile method only supports File.

React Native Version

0.71.11

Output of npx react-native info

System:
OS: macOS 13.4
CPU: (8) arm64 Apple M1 Pro
Memory: 67.23 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.1.0 - ~/.nvm/versions/node/v19.1.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v19.1.0/bin/yarn
npm: 9.3.1 - ~/.nvm/versions/node/v19.1.0/bin/npm
Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.1 - /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: Flamingo 2022.2.1 Patch 2 Flamingo 2022.2.1 Patch 2
Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.11 => 0.71.11
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Create new react-native project, edit app.tsx and try to use the common "new File()" command.

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

no

@cortinico
Copy link
Contributor

In react-native there is no class "File". It would make Uploads easier with appwrite because their storage.createFile method only supports File.

Which langauge are you referring to? JS/Java/Kotlin/ObjC/C++?
Also what is appwrite?
Could you link a reference to storage.createFile?

@trashcoder
Copy link
Contributor Author

trashcoder commented Jun 26, 2023

I'm referring to Javascript.

Appwrite is a backend platform like firebase: https:/appwrite.io

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jun 26, 2023
@cortinico
Copy link
Contributor

Could you link a reference to storage.createFile?

@cortinico cortinico added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Jun 26, 2023
@trashcoder
Copy link
Contributor Author

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jun 26, 2023
@trashcoder
Copy link
Contributor Author

Now that i'm a little bit familiar with the react-native code i see, that there is a File class in the library:
packages/react-native/Libraries/Blob/File.js

But this Class does not show up in my IDEs like webstorm or VSCode. Is there something wrong with its export?

@cortinico
Copy link
Contributor

But this Class does not show up in my IDEs like webstorm or VSCode. Is there something wrong with its export?

Yup that's most likely because we are not exporting Blob from the index.js file (not sure why this is the case). You should be able to import that File.js file directly though in your project

@trashcoder
Copy link
Contributor Author

trashcoder commented Jun 27, 2023

Sorry, but i can't import the class File directly.
I tried ist this way:

import File from 'react-native/Libraries/Blob/File.js';
const file = new File(blob, "test.jpg");

and get a undefined is not a function.

@trashcoder
Copy link
Contributor Author

I found out, that File is missing in the file "globals.d.ts". I'll make a pull request to add the declaration.

facebook-github-bot pushed a commit that referenced this issue Jul 4, 2023
Summary:
In Webstorm or VSCode when using Typescript the declaration of the class "File" is missing. So both IDEs show "File" as error. With this change it fixes the issue #38061 .

## Changelog:
[GENERAL] [FIXED] Fixed missing File declaration in Typescript global.d.ts
<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: #38165

Test Plan:
I ran
`yarn run test-typescript`
with no error

After that i initialized a new react-native project and installed the react-native library with my local changes of global.d.ts. Webstorm and VSCode now find the declaration of "File" and don't show "File" as error and suggest the right parameters.

Reviewed By: rshest

Differential Revision: D47209461

Pulled By: cortinico

fbshipit-source-id: 0884dfe786ea3a5070aa0a487a8e74463c8f1a0f
@NickGerleman
Copy link
Contributor

You should be able to import that File.js file directly though in your project

With limited exceptions, almost all of RN’s public JS APIs should be imported directly from “react-native”. Concrete “.js” files should generally not be imported. We will be limiting the ability to do this for files not meant to be public in the future via the “package.json” exports field.

@NickGerleman
Copy link
Contributor

Closing bc the PR was merged.

@trashcoder
Copy link
Contributor Author

With limited exceptions, almost all of RN’s public JS APIs should be imported directly from “react-native”. Concrete “.js” files should generally not be imported. We will be limiting the ability to do this for files not meant to be public in the future via the “package.json” exports field.

Yes, i thought that importing File cannot be the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants