所以我有以下带有 typescript-eslint 的代码及其推荐的设置。我已阅读:在 Next.js 中使用 getInitialProps 和 TypeScript
const X: NextPage = props => {/*...*/}
X.getInitialProps = async (ctx): Promise<unknown> => {/*...*/}
X.getInitialProps
发出此错误:
ESLint:避免引用可能导致无意范围界定的未绑定方法
this
。(@typescript-eslint/unbound-method)
我相信这个问题可能会扩展到,如何正确键入静态方法。
对于那些不熟悉 Next.js 的人,NextPage
有以下(简化的)定义:
export type NextPage<C, IP = {}, P = {}> = ComponentType<P> & { // ComponentType is a React type
getInitialProps?(context: C): IP
}