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

Improve TS typing #168

Closed
wants to merge 8 commits into from
Closed

Conversation

jeremy-rifkin
Copy link

@jeremy-rifkin jeremy-rifkin commented Oct 15, 2022

This is an attempt to fix #167

I do not believe it's correct to suggest the DOMParser implements globalThis.DOMParser, the HTMLElement implements globalThis.HTMLElement, etc.

I think these changes should be ok given the goal of the library is to be close but not too close to the actual dom API.
Perhaps one of the original authors can lend insight into the original motivation for these implements annotations.

Todo:

  • Fix remaining errors
  • Add an automated test case to ensure the library can be imported without errors

@jeremy-rifkin
Copy link
Author

jeremy-rifkin commented Oct 15, 2022

resolved

@jeremy-rifkin
Copy link
Author

I think that is the right fix

@jeremy-rifkin jeremy-rifkin marked this pull request as ready for review October 15, 2022 20:07
@WebReflection
Copy link
Owner

oh gosh ... all definition files are automatically generated per each CI build step or locally before pushing to npm. Apologies I should've mentioned this as this PR is quite some effort if it was fixed manually per each generated file, but next release will re-create again all files and all changes will be lost.

The files you need to eventually change are in the esm folder, not in the types one, as that's all automation.

@jeremy-rifkin
Copy link
Author

Oh shoot thanks! This PR was fast - just a bunch of regex replaces - so nothing of value lost. I’ll make the correct changes when I’m back at my computer.

@jeremy-rifkin
Copy link
Author

I noticed types/dom, types/html, types/interface, types/mixin, types/shared, types/svg,types/xml, and types/index.d.ts were not being auto-generated and haven't seen modifications in a very long time and the structure is the same as types/esm. I deleted these stale files.

readonly CAPTURING_PHASE: number;
readonly NONE: number;
};
declare const GlobalCustomEvent: any;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be correct, maybe this should actually implement globalThis.CustomEvent

@jeremy-rifkin jeremy-rifkin marked this pull request as draft October 16, 2022 18:05
@jeremy-rifkin
Copy link
Author

At the moment there are a lot of types that are not right. Examples from the readme don't work.

@WebReflection
Copy link
Owner

I'm afraid this PR needs some linting adjustment or the CI won't be happy ... and I care about 100% code coverage and happy CI here. Please have a look and yes, exceptions accepted for linters!

@jeremy-rifkin jeremy-rifkin marked this pull request as ready for review October 17, 2022 17:34
@jeremy-rifkin
Copy link
Author

I think this PR is good to go

@iMrDJAi
Copy link

iMrDJAi commented Oct 20, 2022

oh gosh ... all definition files are automatically generated per each CI build step or locally before pushing to npm. Apologies I should've mentioned this as this PR is quite some effort if it was fixed manually per each generated file, but next release will re-create again all files and all changes will be lost.

The files you need to eventually change are in the esm folder, not in the types one, as that's all automation.

@WebReflection Hi, I want to contribute. Could you please explain what's the right way to include types? Are they generated from jsdoc comments?

@@ -25,9 +25,6 @@ const handler = {
}
};

/**
* @implements globalThis.DOMStringMap
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to remove this?

@@ -22,9 +22,6 @@ const update = ({[OWNER_ELEMENT]: ownerElement, value}) => {
);
};

/**
* @implements globalThis.DOMTokenList
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to remove this?

@WebReflection
Copy link
Owner

@jeremy-rifkin

I think this PR is good to go

I just wonder once all "pretending to implement" classes are gone, if TS really helps out or it 'causes just confusion. There are things not really standard that might come up while using this project and I guess what are your thoughts there ... also, those two classes ... I think the implementation conforms with the standard? 🤔 are all implements needed to go?

@WebReflection
Copy link
Owner

@iMrDJAi yes, this JS project uses TSDoc and generates automatically types at build time.

@jeremy-rifkin
Copy link
Author

I just wonder once all "pretending to implement" classes are gone, if TS really helps out or it 'causes just confusion. There are things not really standard that might come up while using this project and I guess what are your thoughts there ... also, those two classes ... I think the implementation conforms with the standard? 🤔 are all implements needed to go?

Thanks for taking a look! It may very well be these two classes do actually implement everything from their globalThis counterparts - I can re-introduce these implements annotations.

I think the one "pretending to implement" part remaining is whatever is returned by Document.defaultView. Alternatively to having it this function return a Proxy that's typed as typeof globalThis & { document: globalThis.Document & Document; }; we could make a proper class / type for exactly what a linkedom document view is. This would address the issue of non-standard things coming up.

@WebReflection
Copy link
Owner

this PR has conflicts ... please resolve those and I'd be happy to move forward, thanks!

@WebReflection
Copy link
Owner

no answer in years ... closing.

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.

Typescript type errors
3 participants