TS17019

'?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'URLSearchParams | undefined'?

Broken Code ❌

export async function* getPageGenerator<ItemType extends z.ZodTypeAny>(
  apiClient: AxiosInstance,
  url: string,
  itemSchema: ItemType,
  params: URLSearchParams? = new URLSearchParams()
) {}

Solution:

Correct the parameter type declaration by using | undefined for optional parameters.

Fixed Code ✔️

export async function* getPageGenerator<ItemType extends z.ZodTypeAny>(
  apiClient: AxiosInstance,
  url: string,
  itemSchema: ItemType,
  params: URLSearchParams | undefined = new URLSearchParams()
) {}