向React应用添加流程似乎很容易,可以在此处看到显示错误的简单示例:
Props2 = {
name: string,
}
class _TestComponent extends Component<Props2> {
render() {
return <div>{this.props.name}</div>
}
}
export function TestFunc(props: {}) {
return <_TestComponent/>
}
这将返回错误Cannot create _TestComponent element because property name is missing in props [1] but exists in Props2 [2].
但是,在混合中添加MobX
时,类型检查会突然停止工作。当我尝试创建观察者时,流根本不提供任何类型信息:
type Props2 = {
name: string,
}
class _TestComponent extends Component<Props2> {
render() {
return <div>{this.props.name}</div>
}
}
export const TestComponent = observer(_TestComponent);
export function TestFunc(props: {}) {
return <TestComponent/>
}
显示No errors!
如果我尝试将TestComponent
更新为特定类型:
export const TestComponent:_TestComponent = observer(_TestComponent);
显示一个非常隐秘的错误:Cannot create TestComponent element because _TestComponent [1] is not a React component.
这是否意味着流量和mobx本质上是不兼容的?由于mobx使用高阶函数来完成“魔术”的事实?