Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type of exported failure helpers from class to interface #12986

Open
eltigerchino opened this issue Nov 11, 2024 · 0 comments · May be fixed by #13036
Open

Change type of exported failure helpers from class to interface #12986

eltigerchino opened this issue Nov 11, 2024 · 0 comments · May be fixed by #13036
Milestone

Comments

@eltigerchino
Copy link
Member

eltigerchino commented Nov 11, 2024

Through this I'm realizing just now that we're not returning "is this interface" but rather "is this class" from that. We should definitely change it for the new function to refer to the interface instead, not sure if it's seen as a breaking change to change it for the others, too

Originally posted by @dummdidumm in #12878 (comment)

class HttpError_1 {
constructor(status: number, body: {
message: string;
} extends App.Error ? (App.Error | string | undefined) : App.Error);
status: number;
body: App.Error;
toString(): string;
}
class Redirect_1 {
constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string);
status: 301 | 302 | 303 | 307 | 308 | 300 | 304 | 305 | 306;
location: string;
}

Proposed solution

Change the types to use the interface instead of the class.

/**
 * Checks whether this is an action failure thrown by {@link fail}.
 * @param {unknown} e The object to check.
- * @return {e is ActionFailure}
+ * @return {e is import('./public.js').ActionFailure}
 */
export function isActionFailure(e) {
	return e instanceof ActionFailure;
}

/**
* Checks whether this is an error thrown by {@link error}.
* @template {number} T
* @param {unknown} e
* @param {T} [status] The status to filter for.
* @return {e is (HttpError & { status: T extends undefined ? never : T })}
*/
export function isHttpError(e, status) {
if (!(e instanceof HttpError)) return false;
return !status || e.status === status;
}

/**
* Checks whether this is a redirect thrown by {@link redirect}.
* @param {unknown} e The object to check.
* @return {e is Redirect}
*/
export function isRedirect(e) {
return e instanceof Redirect;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant