我有一个存储对象,如下所示:
import AsyncStorage from "react-native";
const deviceStorage = {
async saveItem(key, value) {
try {
await AsyncStorage.setItem(key, value);
} catch (error) {
console.log('AsyncStorage Error: ' + error.message);
}
}
};
export default deviceStorage;
setItem
抛出错误
Property 'setItem' does not exist on type 'typeof import("/Users/Developer/React/reactRallyApp/node_modules/@types/react-native/index")'
我看不到为什么会发生或如何解决,我在这里遗漏了一些简单的东西吗?
答案 0 :(得分:1)
您可以这样做:
import { AsyncStorage } from "react-native";
const saveItem = async (key, value) => {
try {
await AsyncStorage.setItem(key, value);
} catch (error) {
console.log('AsyncStorage Error: ' + error.message);
}
}
};
export default saveItem;