In our Typescript app, we frequently use the zod .catch
helper (see here) to add fallback behavior to schemas used to validate API data. These schema setups are being incorrectly flagged by the prefer-top-level-await
rule as promises that should be given a top-level await instead.
Example:
import z from "zod";
const someSchema = z.string().catch("");
This rule just appears to error based on name, so this issue exists for any method called catch
. These also both error:
const objectWithCatch = {
catch: () => undefined,
};
objectWithCatch.catch(); // errors
const getCatchMethod = () => ({
catch: () => undefined,
});
getCatchMethod().catch();
It would be great to pull typing information into this rule to make sure that the catch
in question actually pertains to a promise.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too