Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): add this typings to actions #32210

Merged
merged 2 commits into from
Aug 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ export interface NodePluginArgs {
* }
* }
*/
loadNodeContent(node: Node): Promise<string>
loadNodeContent(this: void, node: Node): Promise<string>

/**
* Internal redux state used for application state. Do not use, unless you
Expand All @@ -953,7 +953,7 @@ export interface NodePluginArgs {
* @example
* const allNodes = getNodes()
*/
getNodes(): Node[]
getNodes(this: void): Node[]

/**
* Get single node by given ID.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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<TContext = Record<string, unknown>>(
this: void,
args: Page<TContext>,
plugin?: ActionPlugin,
option?: ActionOptions
Expand All @@ -1084,6 +1085,7 @@ export interface Actions {

/** @see https://www.gatsbyjs.org/docs/actions/#createNode */
createNode<TNode = Record<string, unknown>>(
this: void,
node: NodeInput & TNode,
plugin?: ActionPlugin,
options?: ActionOptions
Expand All @@ -1094,6 +1096,7 @@ export interface Actions {

/** @see https://www.gatsbyjs.org/docs/actions/#createNodeField */
createNodeField(
this: void,
args: {
node: Node
name?: string
Expand All @@ -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<string, unknown> & { id: string },
plugin?: ActionPlugin
): void

/** @see https://www.gatsbyjs.org/docs/actions/#createJobV2 */
createJobV2(
this: void,
job: {
name: string
inputPaths: string[]
Expand All @@ -1149,18 +1157,24 @@ export interface Actions {

/** @see https://www.gatsbyjs.org/docs/actions/#setJob */
setJob(
this: void,
job: Record<string, unknown> & { 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<string, unknown>, plugin?: ActionPlugin): void
setPluginStatus(
this: void,
status: Record<string, unknown>,
plugin?: ActionPlugin,
): void;

/** @see https://www.gatsbyjs.org/docs/actions/#createRedirect */
createRedirect(
this: void,
redirect: {
fromPath: string
isPermanent?: boolean
Expand All @@ -1176,13 +1190,15 @@ export interface Actions {

/** @see https://www.gatsbyjs.org/docs/actions/#addThirdPartySchema */
addThirdPartySchema(
this: void,
args: { schema: object },
plugin?: ActionPlugin,
traceId?: string
): void

/** @see https://www.gatsbyjs.org/docs/actions/#createTypes */
createTypes(
this: void,
types:
| string
| GraphQLOutputType
Expand All @@ -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<string>; plugins?: Array<string> },
exclude?: { types?: Array<string>; plugins?: Array<string> },
Expand Down