Closed matthewtgilbride closed 4 years ago
@MarcMcIntosh let me know your thoughts...
Hi @matthewtgilbride
so I'm taking a look at gatsby/index.d.ts
as well. soecifically lines 136 to 142.
type RenderCallback<T = any> = (data: T) => React.ReactNode
export interface StaticQueryProps<T = any> {
query: any
render?: RenderCallback<T>
children?: RenderCallback<T>
}
and I'm wondering if
export type StaticQueryRender<T> = Required<StaticQueryProps<T>>['render'];
is similar to
type RenderCallback<T = any> = (data: T) => React.ReactNode
You can also add your name to the contributors in the package.json btw :)
Hi @matthewtgilbride so I'm taking a look at
gatsby/index.d.ts
as well. soecifically lines 136 to 142.type RenderCallback<T = any> = (data: T) => React.ReactNode export interface StaticQueryProps<T = any> { query: any render?: RenderCallback<T> children?: RenderCallback<T> }
and I'm wondering if
export type StaticQueryRender<T> = Required<StaticQueryProps<T>>['render'];
is similar totype RenderCallback<T = any> = (data: T) => React.ReactNode
Yep, so the problem is that type RenderCallback...
isn't exported, so the only way to access it is via the lookup type StaticQueryProps['render']`.
Then, I'm wrapping that in Required
to make it non-optional (I'm not sure why it's optional in the first place...if there is a use case for using the StaticQuery
component without actually rendering anything, please educate me).
You can also add your name to the contributors in the package.json btw :)
OK : - >
@MarcMcIntosh I've adjusted this change to have the smallest surface area possible. Basically, making the render
argument as well as the return type be (data: Data) => JSX.Element
satisfies the compiler in the case withPreview
is used in conjunction with the StaticQuery
HOC.
Using it with the useStaticQuery
hook compiles both before and after this change.
Once this is merged I will remove the type assertions from the typescript example (PR #24).
Neet, thanks :)
The return type of withPreview.tsx was not explicitly declared before, leaving typescript to infer it. The inferred type was not compatible with what gatsby's StaticQuery component expected, causing users to need to cast it themselves, which is less than ideal.