带有 @typescript-eslint/unbound-method 的 TypeScript NextPage 函数 getInitialProp 静态方法
TypeScript NextPage function getInitialProp static method with @typescript-eslint/unbound-method
所以我有以下代码,其中 typescript-eslint 开启了它的推荐设置。我已阅读:
const X: NextPage = props => {/*...*/}
X.getInitialProps = async (ctx): Promise<unknown> => {/*...*/}
X.getInitialProps
发出此错误:
ESLint: Avoid referencing unbound methods which may cause unintentional scoping of 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
}
typescript-eslint 的 GitHub 仓库最近合并了一个修复问题的拉取请求 https://github.com/typescript-eslint/typescript-eslint/pull/1736
所以我有以下代码,其中 typescript-eslint 开启了它的推荐设置。我已阅读:
const X: NextPage = props => {/*...*/}
X.getInitialProps = async (ctx): Promise<unknown> => {/*...*/}
X.getInitialProps
发出此错误:
ESLint: Avoid referencing unbound methods which may cause unintentional scoping of
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
}
typescript-eslint 的 GitHub 仓库最近合并了一个修复问题的拉取请求 https://github.com/typescript-eslint/typescript-eslint/pull/1736