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

Typescript support for jest? #504

Closed
andrehadianto opened this issue Dec 7, 2020 · 11 comments
Closed

Typescript support for jest? #504

andrehadianto opened this issue Dec 7, 2020 · 11 comments
Labels
question General question about usage

Comments

@andrehadianto
Copy link

andrehadianto commented Dec 7, 2020

As the title implies, is there typescript support for @react-native-async-storage/async-storage?

I figured in other discussions that the @types should be the same as the original react-native async-storage or the predecessor react-native-community async-storage. However, I don't know how to implement the previous types on this module.

Instructions would be appreciated!

Could not find a declaration file for module '@react-native-async-storage/async-storage/jest/async-storage-mock'
@andrehadianto andrehadianto changed the title Typescript support? Typescript support for jest? Dec 7, 2020
@krizzu krizzu added the question General question about usage label Dec 7, 2020
@invm
Copy link

invm commented Dec 24, 2020

What I did was to go to
node_modules/@react-native-async-storage/async-storage/types/index.d.ts

copied the whole block down, and changed the name to:
declare module '@react-native-async-storage/async-storage/jest/async-storage-mock' {...}

I do not know if it is the right approach, if it is, someone could do a PR and solve the issue for the next person.

@jklimcak
Copy link

Would also like this supported. When I follow your jest-setup in my TS project, I get:

[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

@invm
Copy link

invm commented Jan 2, 2021

@JoeKlimcak
Did you try doing what I did?

@krizzu
Copy link
Member

krizzu commented Jan 8, 2021

Typescript issue comes from the fact that the mock is not declared in our typings. In that case, I advise to use Jest setup file to mock AsyncStorage

@tido64
Copy link
Member

tido64 commented Feb 12, 2021

Closing due to inactivity. If you think this is a mistake, please reply and we'll reopen it.

@tido64 tido64 closed this as completed Feb 12, 2021
@Guicbdiniz
Copy link

Closing due to inactivity. If you think this is a mistake, please reply and we'll reopen it.

I'm having the same issue here with the import.
Although I'm able to import import AsyncStorage from "@react-native-async-storage/async-storage", I get a type error when importing import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'

@MatkoMilic
Copy link

Having the same issue as the comment saying: I'm having the same issue here with the import.
Although I'm able to import import AsyncStorage from "@react-native-async-storage/async-storage", I get a type error when importing import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'

@bytehala
Copy link

This shouldn't have been closed. The mocks are still not typed. Converting your jest setup from JS to TS will yield the error everyone is talking about.

@tido64
Copy link
Member

tido64 commented May 18, 2022

I think this might be addressed by #805. Please test it and let me know how it goes.

@bytehala
Copy link

@tido64 I'm taking a look now.

@jkdowdle
Copy link

I think this might be addressed by #805. Please test it and let me know how it goes.

Updating appeared to solve the issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question about usage
Projects
None yet
Development

No branches or pull requests

9 participants