-
-
Notifications
You must be signed in to change notification settings - Fork 420
Open
Labels
bugtypesIssues that happen in TypeScript or that require typesIssues that happen in TypeScript or that require types
Description
Describe the bug
The rule unicorn/prefer-top-level-await reports a false positive when using z.catch from Zod Mini (https://github.com/colinhacks/zod). Example code:
const paramsSchema = z.catch(
z.object({
q: z.optional(z.string()),
page: z._default(z.coerce.number(), 1),
}),
{
q: undefined,
page: 1,
}
);This triggers the error:
Prefer top-level await over using a promise chain. (unicorn/prefer-top-level-await)
However, z.catch is not a promise chain or async code, but a schema utility from Zod. This is a false positive.
To Reproduce
- Use Zod Mini's
z.catchin a file witheslint-plugin-unicornenabled. - Observe the false positive error from
unicorn/prefer-top-level-await.
Expected behavior
No error should be reported for this usage, as it is not related to promises or async code.
Environment
- zod: ^3.25.67
- eslint: ^9.29.0
- eslint-plugin-unicorn: ^59.0.1
- Node.js: 22.16.0
akodkod, dawsonbooth, jahusa02, alexw-at, yf-yang and 1 more
Metadata
Metadata
Assignees
Labels
bugtypesIssues that happen in TypeScript or that require typesIssues that happen in TypeScript or that require types