Skip to content

fix: correct container and baseElement typings #266

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

Closed
wants to merge 1 commit into from
Closed

fix: correct container and baseElement typings #266

wants to merge 1 commit into from

Conversation

SavePointSam
Copy link
Contributor

adjusts the typings of container and baseElement to better correlate to their real world application. fixes #265.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Oh nice! So a Node is a subclass of HTMLElement that has a firstChild then?

@SavePointSam
Copy link
Contributor Author

SavePointSam commented Jan 15, 2019

HTMLElements do not have a firstChild property as it hasn't been added to the render tree. A Node does have a firstChild as it has been rendered in some way from being an HTMLElement and exists in a tree structure.

@SavePointSam
Copy link
Contributor Author

I'm not 100% sure that is the best typing, but it accomplishes what we need as we aren't in full control of the renderer and it's typing. This is also the best I could find. It may break in the future if the response of react's renderer doesn't happen to match the API of a DOM Node.

@SavePointSam
Copy link
Contributor Author

It be more accurate we would need to dig into React DOM more and determine what the actual typing of the render response is.

@kentcdodds
Copy link
Member

Well, we're adding typings to container and baseElement both of which we create ourselves so we know their type and it's HTMLDivElement for both of them. I think that would be the most accurate.

@SavePointSam
Copy link
Contributor Author

The input types are different than the outputs because they are passed to the react renderer. When I dove into the renderer typings it just generically said Element which doesn't have a type for firstChild, that I could find.

@kentcdodds
Copy link
Member

Right but we create the container and baseElement so we know what type they are. Go ahead and try editing your node_modules to use HTMLDivElement` for both of those and you'll see it works great :)

@SavePointSam
Copy link
Contributor Author

Hmm, I tried it before and it wasn't working. I'll try with HTMLDivElement again later today.

@julienw
Copy link

julienw commented Jan 16, 2019

The hierarchy is (according to MDN):
EventTarget -> Node -> Element -> HTMLElement -> HTMLDivElement
firstChild is defined in Node.
I'm not sure what we're trying to fix here :) What's the specific error you get in #265?

@SavePointSam
Copy link
Contributor Author

@julienw

[ts] Property 'firstChild' does not exist on type 'HTMLElement'. [2339]

@SavePointSam
Copy link
Contributor Author

@kentcdodds, I'm still getting the does not exist error with HTMLDivElement. It only works if I use Node

[ts] Property 'firstChild' does not exist on type 'HTMLDivElement'. [2339]

@SavePointSam
Copy link
Contributor Author

Same with just Element

[ts] Property 'firstChild' does not exist on type 'Element'. [2339]

@julienw
Copy link

julienw commented Jan 18, 2019

Can you please show the full code that's failing for you?

@SavePointSam
Copy link
Contributor Author

I'm working on building a Codesandbox that reproduces the error. However, it appears to be working fine there. Double checking what's different about my development environment.

@SavePointSam
Copy link
Contributor Author

Ok, found my issue. Turns out my repo didn't list "dom" and "dom.iterable" in the lib section of my tsconfig. No type update is needed. I can look at updating the README to have a TypeScript settings section to avoid people hitting this in the future if you would like @kentcdodds.

@kentcdodds
Copy link
Member

Yeah, some docs updates would be appreciated!

@SavePointSam SavePointSam deleted the issue-265_incorrect-typings branch January 21, 2019 22:38
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.

[types] RenderResult.container of type HTMLElement
3 participants