-
Notifications
You must be signed in to change notification settings - Fork 34
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
Inheriting from Error/Exception not possible #351
Comments
Having the same problem, with axios types in my case. Any suggestion on how to fix it? I'm currently having trouble pattern matching axios errors :( |
Hello @not-rusty, if adding At least, that's how I did it in my case. |
Actually, it seems like when adding open System
open Fable.Core
type [<AllowNullLiteral; >] DatabaseError =
// inherit System.Exception
abstract code: string option
let x = unbox<DatabaseError> null
let code = x.code generates export const x = null;
export const code = x.code; but open System
open Fable.Core
type [<AllowNullLiteral; AbstractClass >] DatabaseError =
// inherit System.Exception
abstract code: string option
let x = unbox<DatabaseError> null
let code = x.code generates import { class_type } from "fable-library/Reflection.js";
export class DatabaseError {
constructor() {
}
}
export function DatabaseError$reflection() {
return class_type("Test.DatabaseError", void 0, DatabaseError);
}
export const x = null;
export const code = x["Test.DatabaseError.get_code"](); which is not what we want in the case of a bindings. |
Inheriting from Error/Exception isn't possible:
gets converted into (abbreviated)
Which results in the error
MyError
is an interface, whileError
/Exception
isn't.Possible fix: make it abstract:
Same for other abbreviated types that aren't interfaces.
Making classes with such inheritance abstract would be an issue when no unit-ctor, or sealed type (
Function
->System.Action
). Andabstract
would need to bubble up with more inheritance likeclass MyOtherError extends MyError {}
.The text was updated successfully, but these errors were encountered: