React.useEffect(_ => {
ReactNativeAsyncStorage.getItem("jwt")
|> Js.Promise.then_(jwt => {Js.log(jwt)});
None;
});错误:
This expression has type unit but an expression was expected of type
Js.Promise.t('a) = Js.Promise.t('a)我在https://github.com/react-native-community/async-storage中使用https://github.com/reason-react-native/async-storage
发布于 2020-03-29 01:17:21
Js.Promise.then_的类型为
('a => t('b), t('a)) => t('b)这意味着传递给它的函数必须返回a,而then_本身将返回该promise。
你在代码中犯了两个错误:
传递给then_
then_.返回的promise
下面的命令可以同时修复这两个问题:
React.useEffect(_ => {
let _: Js.Promise.t(unit) =
Js.Prmoise.(
ReactNativeAsyncStorage.getItem("jwt")
|> then_(jwt => resolve(Js.log(jwt)))
);
None;
});let _: Js.Promise.t(unit) = ...使用通配符模式丢弃以下表达式的结果。结果的类型是Js.Result.t(unit),对其进行了注释,以防止意外的局部应用。
resolve(Js.log(jwt))将返回一个promise,其中包含调用Js.log的结果,该promise为unit,因此结果promise的类型为Js.Promise.t(unit)。
有关如何使用promises的更多信息,请参阅Reason documentation。
https://stackoverflow.com/questions/60903956
复制相似问题