Hey everyone! I’m trying to work with DatoCMS and NextJS with Typescript for the first time, and the documentation is not so good unfortunately.
My query returns a Typescript error:
export const getStaticProps: GetStaticProps = async () => {
const data = await request({
query: `query Projects {
allProjects(orderBy: _firstPublishedAt_DESC) {
_firstPublishedAt
id
category
discipline {
name
}
title
headerImagesPortrait {
id
responsiveImage {
height
width
src
base64
}
}
}
}
`,
});
return {
props: {
data,
},
};
};
which returns: Argument of type "{ query: string; }' is not assignable to parameter of type "{ query: any; variables: any; includeDrafts: any; excludelnvalid: any; }'. Type "{ query: string; y' is missing the following properties from type "{ query: any; variables: any; includeDrafts: any; excludelnvalid: any; }': variables, includeDrafts, excludelnvalid
Furthermore, I have a type definition file for this query:
export interface Project {
allProjects: [
{
_firstPublishedAt: string;
id: string;
category: string;
discipline: Array<{
name: string;
}>;
title: string;
headerImagesPortrait: Array<{
id: string;
responsiveImage: Array<{
height: number;
width: number;
src: string;
base64: string;
}>;
}>;
}
];
}
which I have in my index file:
interface Props {
data: [Project];
}
and also returns an error: Property 'allProjects' does not exist on type '[Project]'.
I have a datocms.ts file according to the JS NextJS DatoCMS tutorial which also results in a bunch of errors. Also, the type of <StructuredText>
is unclear to me. I have previously worked with NextJS and Sanity which was working pretty great and I have been using Dato with Gatsby in JS as well. Upgrading to TS however, has been quite difficult for me with Dato.
Thanks for any help!