我正在尝试将继承的 monorepo 从yarn+lerna 转换为 pnpm 工作区
由于反应版本不匹配,我目前收到错误,由于某种原因,打字稿没有选择树中最接近的 @types/react 版本
我有一个使用react 18类型的packages/web包,和一个使用react 16类型的packages/native包。
我在本机包中有很多错误,例如
'Text' cannot be used as a JSX component.
Its instance type 'Text' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'import("~/node_modules/.pnpm/@types+react@16.14.34/node_modules/@types/react/index").ReactNode' is not assignable to type 'import("~/node_modules/.pnpm/@types+react@18.0.14/node_modules/@types/react/index").ReactNode'.
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?
考虑以下代码:
fn foo(x: i32) -> Result<i32, Error> {
//...
}
fn bar(x: Result<i32,Error>) -> Result<i32, Error> {
//...
}
fn main() {
let y = bar(foo(2)).unwrap();
}
Run Code Online (Sandbox Code Playgroud)
这是惯用的,传递Result类型吗?或者你应该bar()在i32直接传递之前处理错误或解开结果。