-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
instanceof
ActionFailure refers to the wrong object.
#10361
Comments
The actual classes are not exported, just their types. This is by design and should error on the type level, no idea when this stopped doing so. |
True, only the types are exported. But This |
That comment is about internal stuff. The classes are loaded in nodejs and vite which means they are not the exact same class/reference. |
Hmm, I see. I think it would be nice to export those classes only as types so the typescript server would complain while trying to instantiate them. I'll leave the issue open for now. |
This can be used as a temporary workaround. import { fail, type ActionFailure as ActionFailureType } from "@sveltejs/kit"
interface Class<T> extends Function {
new (...args: any[]): T
}
export const ActionFailure = fail(Infinity).constructor as unknown as Class<ActionFailureType> |
You can actually do something like this which I think looks better( I was trying to get the constructor for a library of mine ) import { fail, type ActionFailure as ActionFailureType } from "@sveltejs/kit"
export const ActionFailure = fail(Infinity).constructor as typeof ActionFailureType But it'd be great if we didn't had to do this honestly. |
Adding this to the 2.0 milestone - it would be good to fix the type generation or the source of the type generation such that |
- add ActionFailure interface and use that publicly instead of the class. Prevents the false impression that you could do "instanceof" on the return type, fixes #10361 - add uniqueSymbol to ActionFailure instance so we can distinguish it from a regular return with the same shape - fix setup to actually run test/types
* fix: Adjust fail method and ActionFailure type - add ActionFailure interface and use that publicly instead of the class. Prevents the false impression that you could do "instanceof" on the return type, fixes #10361 - add uniqueSymbol to ActionFailure instance so we can distinguish it from a regular return with the same shape - fix setup to actually run test/types * test * regenerate types --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
fixed in #11261, closing |
Describe the bug
When you use
instanceof
on anActionFailure
class, it fails with aTypeError: Right-hand side of 'instanceof' is not an object
.Reproduction
https://gitlab.com/Curstantine/sveltekit-instanceof-runtime
Logs
System Info
Severity
annoyance
Additional Information
This is most likely due to this "grotesque" hack not working.
This is apparent when you directly call an
ActionFailure
.e.g.
The text was updated successfully, but these errors were encountered: