Skip to content

Conversation

cexbrayat
Copy link
Member

@cexbrayat cexbrayat commented May 23, 2020

Adds some typings to the find functions, and handle a case surfaced by TS (but that I did not manage to reproduce via unit tests, so it might never happen).

console.log(reversedChildren)
reversedChildren.forEach(
(node: string | number | boolean | VNodeArrayChildren | VNode) => {
nodes.unshift(node)
Copy link
Member Author

@cexbrayat cexbrayat May 23, 2020

Choose a reason for hiding this comment

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

I need help here, please.
If I follow correctly until that point, children is of type VNodeNormalizedChildren.
That means its elements, after filtering the potential null/undefined ones (which I added to be safe), can be either string | number | boolean | VNodeArrayChildren | VNode (see https://github.com/vuejs/vue-next/blob/24168bbb333727417ddcb310c615afc55ee923ad/packages/runtime-core/src/vnode.ts#L85-L92) . The current code considers it is always a VNode. Can we be sure of that?
If yes, I can force the cast and add a comment explaining why.
If no, we need to handle the other cases, but I'm not sure what needs to be done.
cc @dobromir-hristov

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I was just collecting all children, then in the match I am filtering away the unnecessary.
Children can be other things, but I did not yet find such cases cases.

String means its just a plain DOM element.
VNode is Vue component instance.
Boolean I have no idea when 😆
VNodeArrayChildren is probably for multi root components? idk.. :/

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I did not manage to reproduce a case where we have VNodeArrayChildren either. To be safe, I added a branch if we end up with it, and call aggregateChildren on them. We should be safe in all cases.

@cexbrayat cexbrayat force-pushed the chore/strict-ts-find branch from b55916d to 06aa50d Compare May 24, 2020 08:59
@cexbrayat cexbrayat marked this pull request as ready for review May 24, 2020 09:02
@cexbrayat
Copy link
Member Author

The PR is now up for review.

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Quite difficult to review this (I don't have a ton of context on this part of the codebase).

Not exactly sure how useful these particular types are, but I don't think it makes the codebase worse by any means. Just left one comment!

@lmiller1990 lmiller1990 merged commit 087846b into vuejs:master May 26, 2020
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.

3 participants