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

The 'gatsby' Node module needs a type parameter appended to GatsbyAPIFunctionResponse #31135

Closed
nwehner opened this issue Apr 30, 2021 · 1 comment · Fixed by #31182
Closed
Labels
topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript type: bug An issue or pull request relating to a bug in Gatsby

Comments

@nwehner
Copy link

nwehner commented Apr 30, 2021

Description

The latest version of Gatsby in NPM-land, 3.2.1, won't compile with the standard TypeScript compiler (i.e. by running tsc) because the "Type 'GatsbyAPIFunctionResponse' is not generic.".

It appears the GatsbyAPIFunctionResponse interface from node_modules/gatsby/index.d.ts is automatically generated, as I can't find a single instance of it being created in the GitHub codebase. The interface simply needs the type parameter appended to it for the type to be correct.

Steps to reproduce

Opening up the node_modules/gatsby/index.d.ts file in any IDE will show the missing type parameter error.

Incorrect type

/**
* Gatsby API Function route response
*/
export interface GatsbyAPIFunctionResponse extends ServerResponse {
/**
* Send "any" data in response
*/
send: Send<T>
/**
* Send "JSON" data in response
*/
json: Send<T>
/**
* Set the HTTP status code of the response
*/
status: (statusCode: number) => GatsbyAPIFunctionResponse<T>
redirect(url: string): GatsbyAPIFunctionResponse<T>
redirect(status: number, url: string): GatsbyAPIFunctionResponse<T>
}

Correct type

The GatsbyAPIFunctionResponse just needs the type parameter appended to it so the compiler knows what T means within the interface.
/**
* Gatsby API Function route response
*/
export interface GatsbyAPIFunctionResponse<T> extends ServerResponse {
...
}

@nwehner nwehner added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 30, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 30, 2021
@maximeg
Copy link

maximeg commented May 2, 2021

Same thing.

The thing seems to have been renamed to GatsbyFunctionResponse in master, but the issue is still there.

@LekoArts LekoArts added topic: functions topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 3, 2021
@LekoArts LekoArts added the topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) topic: TypeScript Issues and PRs related to TS in general, public typings or gatsby-plugin-typescript type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants