0

所以我有以下带有 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
}
4

1 回答 1

0

typescript-eslint 的 GitHub 存储库最近合并了一个拉取请求以解决该问题https://github.com/typescript-eslint/typescript-eslint/pull/1736

于 2020-04-13T06:35:26.593 回答