You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I try to extend the Fraction type with a specific class to add the ability to use non reduced fractions. I would like to extend Fraction class to keep benefits of all existing types conversion and operations with Fraction when I don't overide them in my own custom Element_Fraction class.
returns Fraction object, thus the implementation doesn't work.
I try with multiply, divide it occurs the same result. At the end, only "add" works, and it's pretty wierd.
Workaround
When I remove the heritance of Element_Fraction
export class Element_Fraction {
all operations works and returns my custom class. But unfortunaltly, I loose benefits of all exsting conversions and operations already implemented in Fraction.
To Reproduce
Implement the class Element_Fraction and Element_Fraction type declarations
Try : math.add((new Element_Fraction(2,4)),(new Element_Fraction(8,4))) // it returns Element_Fraction object
Try : math.subtract((new Element_Fraction(2,4)),(new Element_Fraction(8,4))) // it returns Fraction object instead of Element_Fraction object
I may not have implemented my idea in the right way, so don't hesitate to tell me if it could be another approach to reach my initial objective.
Thanks,
Chris
The text was updated successfully, but these errors were encountered:
I haven't tested, but I think the issue may originate from Element_Fraction being both identified as Element_Fraction and as Fraction. The detection of Fraction is as follows:
The issue probably resolves when you change the Element_Fraction class such that isFraction returns false, I think setting a property .isFraction = false on the class should do the trick.
Hello,
I try to extend the Fraction type with a specific class to add the ability to use non reduced fractions. I would like to extend Fraction class to keep benefits of all existing types conversion and operations with Fraction when I don't overide them in my own custom Element_Fraction class.
Here the simple following class :
I've also added the type declaration for my custom Element_Fraction
The bug
returns and Element_Fraction thus the implementation works well with the "add"
returns Fraction object, thus the implementation doesn't work.
I try with multiply, divide it occurs the same result. At the end, only "add" works, and it's pretty wierd.
Workaround
When I remove the heritance of Element_Fraction
all operations works and returns my custom class. But unfortunaltly, I loose benefits of all exsting conversions and operations already implemented in Fraction.
To Reproduce
I may not have implemented my idea in the right way, so don't hesitate to tell me if it could be another approach to reach my initial objective.
Thanks,
Chris
The text was updated successfully, but these errors were encountered: