Closed pragdave closed 4 years ago
ElementAlias is not an interface. It is just all svg.js types as a union. You would need an interface with ALL the methods which are available on any element of svg.js.
But if we said:
class ForeignObject extends ... implements Rect {
}
then wouldn't that means that it would be typed to include all the methods in Rect? So wouldn't the union type say 'all the methods in any of these..."?
I honestly have no idea if you can implement Unions. Also: if you implement them you must actually write them out in the typings and thats what I wanted to avoid.
Note to myself: I need to add SVGForeignObjectElement to the typeMappings in the d.ts file
So I just spent a couple of hours messing around with trying to get a safe typing for List. I've learned a lot about keyof, indexing, and mixins, but I don't seem to be able to create something as dynamic as we need. It's on my back burner of things to think about while asleep.
In the meantime, this PR has turned into something of a mess. I'd like to get at least some of it merged, just because it fixes a lot of errors I'm seeing here. This might be a case where pragmatism beats perfection :)
Would it be best to close this PR and open another? Or do you know what you're happy to merge?
So I just spent a couple of hours messing around with trying to get a safe typing for List. I've learned a lot about keyof, indexing, and mixins, but I don't seem to be able to create something as dynamic as we need
Yes, I honestly thought, that a string-index-key as I tried would allow this but you can either have that OR other methods. Because all the array methods have to follow the string-index signature, too. Its stupid. Thats why it cannot really be typed and that is really unfortunate.
In the meantime, this PR has turned into something of a mess. I'd like to get at least some of it merged, just because it fixes a lot of errors I'm seeing here. This might be a case where pragmatism beats perfection :)
I honestly lost track a bit :D. I will have a look which conversation can be resolved and will do a last review of what needs to be changed explicitely. Maybe I just change it myself if that works over the browser. And then we can merge :)
I found that I was getting type errors with Lists when it was an interface, but if I changed it to a class and tightened up the callback function and return types it was OK.
I also added the ForeignObject class and helper function in Containers