Next.js Discord

Discord Forum

generateStaticParams wrong types

Answered
Cape May Warbler posted this in #help-forum
Open in Discord
Cape May WarblerOP
export async function generateStaticParams(): Promise<typeof positionsArray> {
    return positionsArray as typeof positionsArray;
}

Where my positions array looks like:
export const positionsArray = [
    "welder",
    "assembler",
    "grinder",
    "crane-operator",
    "cnc-operator",
    "welding-engineer",
    "blacksmith"
] as const;

And Error I get is:
Type error: Type '{ __tag__: "generateStaticParams"; __return_type__: Promise<readonly ["welder", 
"assembler", "grinder", "crane-operator", "cnc-operator", "welding-engineer", "blacksmith"]>; }' does not satisfy the constraint '{ __tag__: "generateStaticParams"; __return_type__: any[] | Promise<any[]>; }'.
  Types of property '__return_type__' are incompatible.
    Type 'Promise<readonly ["welder", "assembler", "grinder", "crane-operator", "cnc-operator", "welding-engineer", "blacksmith"]>' is not assignable to type 'any[] | Promise<any[]>'.
      Type 'Promise<readonly ["welder", "assembler", "grinder", "crane-operator", "cnc-operator", 
"welding-engineer", "blacksmith"]>' is not assignable to type 'Promise<any[]>'.
        The type 'readonly ["welder", "assembler", "grinder", "crane-operator", "cnc-operator", "welding-engineer", "blacksmith"]' is 'readonly' and cannot be assigned to the mutable type 'any[]'.

Can't find solution for that and would be thankful for any help
Answered by Cape May Warbler
I didn't have to provide return type for generateStaticParams, this was whole cause of error
View full answer

1 Reply

Cape May WarblerOP
I didn't have to provide return type for generateStaticParams, this was whole cause of error
Answer