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

fix: add Fragment declaration in svg.js.d.ts #1309

Merged
merged 3 commits into from
Aug 18, 2023

Conversation

we125182
Copy link
Contributor

this pr is to fix issue #1307 .

@Fuzzyma
Copy link
Member

Fuzzyma commented Aug 14, 2023

Would it make sense to let fragment simply extend from Container to avoid duplication?

@we125182
Copy link
Contributor Author

Actually, I thought in this way. After read source code, find that Container extends Element, but Fragment extends Dom. if Fragment extends Container, it'll has Element methods, but Fragment doesn't have methods of Element

@Fuzzyma
Copy link
Member

Fuzzyma commented Aug 15, 2023

mh, maybe you can add an interface "Containerable" which has all the methods and both fragment and container extend from it

@we125182
Copy link
Contributor Author

I tried the Interface way. But implements Containerable Interface, you need define same medthods too. in this way, need define same method three times(Containerable, Fragment, Container). Certanlly use interface can ensure Container and 'Frament` has same Constuct Element methods.

image

try on TS PLAYGROUND

@Fuzzyma
Copy link
Member

Fuzzyma commented Aug 16, 2023

Alright, last straw: use a class instead of an interface as intermediate layer. But don't export that class since it doesn't exist

@we125182 we125182 force-pushed the 1307-add-Frament-declaration branch from 9e89f24 to b4163a8 Compare August 17, 2023 06:31
@we125182
Copy link
Contributor Author

I use the dynamic extends to avoid dupliacted declarations. But the temp varibles(ContainableDom, ContainableElement) always export. which means user can import them, actually they didn't exist. I add comment to explain. Maybe there has a good way.

@Fuzzyma
Copy link
Member

Fuzzyma commented Aug 17, 2023

I don't think anyone will ever import them.
If everything else works like intended I would consider this a good solution :).
Does everything work?

if not, while user hover in Container will show DynamicExtends constructor params.
@we125182
Copy link
Contributor Author

Yes, I linked the changed package in a project. Fragment has methods of Containable and Dom. Container keep same behavior.
image

@Fuzzyma
Copy link
Member

Fuzzyma commented Aug 18, 2023

Awesome. Thank you!

@Fuzzyma Fuzzyma merged commit b30f0d6 into svgdotjs:master Aug 18, 2023
@we125182
Copy link
Contributor Author

Glad to help.

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

Successfully merging this pull request may close these issues.

2 participants