From cf9c0669d3351dd09409889975f7efb2520e9e0d Mon Sep 17 00:00:00 2001 From: Alvis Tang Date: Fri, 27 Aug 2021 08:20:23 +0100 Subject: [PATCH] fix(gatsby): add this typings to actions (#32210) avoid unnecessary warnings from @typescript-eslint/unbound-method see https://github.com/typescript-eslint/typescript-eslint/blob/v4.28.0/packages/eslint-plugin/docs/rules/unbound-method.md Co-authored-by: Ward Peeters --- packages/gatsby/index.d.ts | 44 +++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 824e85a162127..5dac0d79685e0 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -931,7 +931,7 @@ export interface NodePluginArgs { * } * } */ - loadNodeContent(node: Node): Promise + loadNodeContent(this: void, node: Node): Promise /** * Internal redux state used for application state. Do not use, unless you @@ -953,7 +953,7 @@ export interface NodePluginArgs { * @example * const allNodes = getNodes() */ - getNodes(): Node[] + getNodes(this: void): Node[] /** * Get single node by given ID. @@ -965,7 +965,7 @@ export interface NodePluginArgs { * @example * const node = getNode(id) */ - getNode(id: string): Node + getNode(this: void, id: string): Node /** * Get array of nodes of given type. @@ -975,7 +975,7 @@ export interface NodePluginArgs { * @example * const markdownNodes = getNodesByType(`MarkdownRemark`) */ - getNodesByType(type: string): Node[] + getNodesByType(this: void, type: string): Node[] /** * Set of utilities to output information to user @@ -993,7 +993,7 @@ export interface NodePluginArgs { * @param path of the node. * @returns Single node instance. */ - getNodeAndSavePathDependency(id: string, path: string): Node + getNodeAndSavePathDependency(this: void, id: string, path: string): Node /** * Key-value store used to persist results of time/memory/cpu intensive @@ -1013,7 +1013,7 @@ export interface NodePluginArgs { * ...restOfNodeData * } */ - createNodeId(input: string): string + createNodeId(this: void, input: string): string /** * Create a stable content digest from a string or object, you can use the @@ -1031,7 +1031,7 @@ export interface NodePluginArgs { * } * } */ - createContentDigest(input: string | object): string + createContentDigest(this: void, input: string | object): string /** * Set of utilities that allow adding more detailed tracing for plugins. @@ -1070,10 +1070,11 @@ export interface BuildArgs extends ParentSpanPluginArgs { export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#deletePage */ - deletePage(args: { path: string; component: string }): void + deletePage(this: void, args: { path: string; component: string }): void /** @see https://www.gatsbyjs.org/docs/actions/#createPage */ createPage>( + this: void, args: Page, plugin?: ActionPlugin, option?: ActionOptions @@ -1084,6 +1085,7 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#createNode */ createNode>( + this: void, node: NodeInput & TNode, plugin?: ActionPlugin, options?: ActionOptions @@ -1094,6 +1096,7 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#createNodeField */ createNodeField( + this: void, args: { node: Node name?: string @@ -1105,39 +1108,44 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#createParentChildLink */ createParentChildLink( + this: void, args: { parent: Node; child: NodeInput }, plugin?: ActionPlugin ): void /** @see https://www.gatsbyjs.org/docs/actions/#setWebpackConfig */ - setWebpackConfig(config: object, plugin?: ActionPlugin): void + setWebpackConfig(this: void, config: object, plugin?: ActionPlugin): void /** @see https://www.gatsbyjs.org/docs/actions/#replaceWebpackConfig */ - replaceWebpackConfig(config: object, plugin?: ActionPlugin): void + replaceWebpackConfig(this: void, config: object, plugin?: ActionPlugin): void /** @see https://www.gatsbyjs.org/docs/actions/#setBabelOptions */ - setBabelOptions(options: object, plugin?: ActionPlugin): void + setBabelOptions(this: void, options: object, plugin?: ActionPlugin): void /** @see https://www.gatsbyjs.org/docs/actions/#setBabelPlugin */ setBabelPlugin( + this: void, config: { name: string; options: object }, plugin?: ActionPlugin ): void /** @see https://www.gatsbyjs.org/docs/actions/#setBabelPreset */ setBabelPreset( + this: void, config: { name: string; options: object }, plugin?: ActionPlugin ): void /** @see https://www.gatsbyjs.org/docs/actions/#createJob */ createJob( + this: void, job: Record & { id: string }, plugin?: ActionPlugin ): void /** @see https://www.gatsbyjs.org/docs/actions/#createJobV2 */ createJobV2( + this: void, job: { name: string inputPaths: string[] @@ -1149,18 +1157,24 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#setJob */ setJob( + this: void, job: Record & { id: string }, plugin?: ActionPlugin ): void /** @see https://www.gatsbyjs.org/docs/actions/#endJob */ - endJob(job: { id: string }, plugin?: ActionPlugin): void + endJob(this: void, job: { id: string }, plugin?: ActionPlugin): void /** @see https://www.gatsbyjs.org/docs/actions/#setPluginStatus */ - setPluginStatus(status: Record, plugin?: ActionPlugin): void + setPluginStatus( + this: void, + status: Record, + plugin?: ActionPlugin, + ): void; /** @see https://www.gatsbyjs.org/docs/actions/#createRedirect */ createRedirect( + this: void, redirect: { fromPath: string isPermanent?: boolean @@ -1176,6 +1190,7 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#addThirdPartySchema */ addThirdPartySchema( + this: void, args: { schema: object }, plugin?: ActionPlugin, traceId?: string @@ -1183,6 +1198,7 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#createTypes */ createTypes( + this: void, types: | string | GraphQLOutputType @@ -1196,12 +1212,14 @@ export interface Actions { /** @see https://www.gatsbyjs.org/docs/actions/#createFieldExtension */ createFieldExtension( + this: void, extension: object, plugin?: ActionPlugin, traceId?: string ): void printTypeDefinitions( + this: void, path?: string, include?: { types?: Array; plugins?: Array }, exclude?: { types?: Array; plugins?: Array },