Skip to content

Improve generic types #4

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

Merged
merged 5 commits into from
May 2, 2022
Merged

Improve generic types #4

merged 5 commits into from
May 2, 2022

Conversation

JuanM04
Copy link
Contributor

@JuanM04 JuanM04 commented Apr 30, 2022

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Continuation of #3. This PR adds better types for map() inspired by the types of unist-util-visit-parents.

@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Apr 30, 2022
@JuanM04 JuanM04 changed the title Generics Improve generic types Apr 30, 2022
@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Apr 30, 2022
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

Nice, thanks Juan! Just a Q / style nit

@@ -0,0 +1,19 @@
import type {Node, Parent} from 'unist'

export type NodeOfTree<
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export type NodeOfTree<
/**
* Internal utility to collect all descendants of in `Tree`.
* @see https://github.com/syntax-tree/unist-util-visit-parents/blob/18d36ad/complex-types.d.ts#L43
*/
export type InclusiveDescendant<

Perhaps good to reference where it comes from?

And, what do you think of that original name, InclusiveDescendant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I though NodeOfTree was more explicit, but I can change it

Copy link
Member

Choose a reason for hiding this comment

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

I understand.
Several terms in unist and friends are also used in other places that deal with trees, including the DOM for example. Descendant and inclusive descendant stem from that.
Some more common terms: https://github.com/syntax-tree/unist#glossary

@wooorm wooorm merged commit 8a4f677 into syntax-tree:main May 2, 2022
@github-actions

This comment has been minimized.

@wooorm wooorm added 🦋 type/enhancement This is great to have ☂️ area/types This affects typings 💪 phase/solved Post is done labels May 2, 2022
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label May 2, 2022
@wooorm
Copy link
Member

wooorm commented May 2, 2022

Released in 3.1.0!

@JuanM04 JuanM04 deleted the generics branch May 2, 2022 15:26
wooorm pushed a commit that referenced this pull request May 3, 2022
Related-to: GH-4.
Closes Gh-5.

Reviewed-by: Titus Wormer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 💪 phase/solved Post is done 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

2 participants