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

Why is there not a @types/gatsby package? #14535

Closed
alexluong opened this issue Jun 4, 2019 · 6 comments
Closed

Why is there not a @types/gatsby package? #14535

alexluong opened this issue Jun 4, 2019 · 6 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@alexluong
Copy link
Contributor

alexluong commented Jun 4, 2019

Hi,

I'm trying out TypeScript with Gatsby for the first time and quite surprised that there is no @types/gatsby package. I think it would be helpful, especially if someone want to implement the Node/Browser/SSR in TypeScript.

Some example code:

export function sourceNodes({ actions, createNodeId }: SourceNodesParam) {}
@gatsbot gatsbot bot added the type: question or discussion Issue discussing or asking a question about Gatsby label Jun 4, 2019
@DSchau
Copy link
Contributor

DSchau commented Jun 4, 2019

Types are available, and are distributed alongside the library.

https://unpkg.com/gatsby@2.8.2/index.d.ts

Hope this helps -- thanks!

@DSchau DSchau closed this as completed Jun 4, 2019
@alexluong
Copy link
Contributor Author

Thanks for the response. This is exactly what I'm looking for.

@alexluong
Copy link
Contributor Author

alexluong commented Jun 4, 2019

@DSchau Sorry for bothering, but using types from Gatsby create a false error for me:

    createNode({
      ...obj,
      id: createNodeId(`Obj-${post.id}`),
      parent: "",
      children: [],
      internal: {
        type: "Obj",
        content: nodeContent,
        contentDigest: crypto
          .createHash("md5")
          .update(nodeContent)
          .digest("hex"),
      },
    })

It complains:

Type '{ type: string; content: string; contentDigest: string; }' is missing the following properties from type '{ type: string; mediaType: string; content: string; contentDigest: string; owner: string; description?: string | undefined; }': mediaType, owner

What I think is happening is here:

export interface Actions {
  ...

  createNode(node: Node, plugin?: ActionPlugin, options?: ActionOptions): void
}

It expects a Node as an argument where mediaType is not optional and owner field exists within internal.

Maybe there should be a NodeInput where mediaType is optional and there is no owner field?

@DSchau
Copy link
Contributor

DSchau commented Jun 4, 2019

@alexluong we'd love a PR making those types a little more flexible!

@alexluong
Copy link
Contributor Author

@DSchau Created a PR with a follow-up question. We can discuss over there! Thanks for the support.

@muescha
Copy link
Contributor

muescha commented Jun 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants