payload
payload copied to clipboard
plugin-seo: Incorrect type for GenerateTitle and other generate functions
The GenerateTitle type does not appear to be correct and the readme example doesn't offer type safety:
generateTitle: ({ doc }) => `Website.com — ${doc.title.value}`,
I believe it should be changed to:
export type GenerateTitle<T = any> = (
args: { doc: T; locale?: string },
) => string | Promise<string>
// useage:
type Project = {
title: string
}
const generateTitleFromProject: GenerateTitle<Project> = function generateTitle({ doc }) { return doc.title };
The suggested typing wouldn't consider that the actual values passed are Fields though, right?
Mixed and matched code snippet to show what the actual args are:
export type Fields = {
[path: string]: FormField;
};
export type FormFieldsContext = [Fields, Dispatch<FieldAction>];
declare const useAllFormFields: () => FormFieldsContextType;
const [fields] = useAllFormFields()
const newHref = await generateURL({
...docInfo,
doc: { fields },
locale,
})
const generatedDescription = await generateDescription({
...docInfo,
doc: { ...fields },
locale,
})
Closing as these types have been updated for V3