【发布时间】:2017-11-16 05:18:33
【问题描述】:
这个 Flow JS 错误是什么意思?
Expected polymorphic type instead of any member of intersection type.
详情:
错误是由Document 在下面的导出行中引发的。我不明白它为什么会发生,或者我能做些什么来解决它。 (我尝试在 Flow 文档中查找这一点,但仍然无法弄清楚。)
// @flow
import Document, {Head, Main, NextScript} from 'next/document'
export default class IntlDocument extends Document {
static async getInitialProps (context) {
const props = await super.getInitialProps(context)
const {req: {localeDataScript}} = context
return {
...props,
localeDataScript
}
}
render () {
return (
<html>
<Head />
<body>
<Main />
<script
dangerouslySetInnerHTML={{
__html: this.props.localeDataScript
}}
/>
<NextScript />
</body>
</html>
)
}
}
next/document 类型声明是这样的:
declare module "next/document" {
import type {Component} from 'react';
declare type Context = {
pathname: string,
query: any,
req?: any,
res?: any,
xhr?: any,
err?: any,
};
declare export var Head: Class<Component<void, *, *>>;
declare export var Main: Class<Component<void, *, *>>;
declare export var NextScript: Class<Component<void, *, *>>;
declare export default Class<Component<void, *, *>> & {
getInitialProps: (ctx: Context) => Promise<*>;
renderPage(cb: Function): void;
};
}
【问题讨论】:
标签: javascript flowtype next.js