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 plugin output type #31

Closed
wants to merge 1 commit into from
Closed

Fix plugin output type #31

wants to merge 1 commit into from

Conversation

andrejpavlovic
Copy link

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

Current

Plugin output type defaults to the input type which is HastRoot

Expected

Plugin output type should be MdastRoot which corresponds to the toHast return type.

Change

Plugin output type set to HastRoot instead of defaulting to the input type MdastRoot.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 31, 2023
@wooorm
Copy link
Member

wooorm commented Apr 1, 2023

Hi!

You are mostly correct.
But there is a comment above this, introduced here: c6a4c64, that mentions it doesn’t work.

There is also the case where the current types are as true as your types: this plugin can be used in bridge mode and in mutate mode. Mutate mode would be typed with your proposal, whereas the current types represent bridge mode.

I don’t know exactly why I wrote that comment anymore. My guess is that TypeScript sometimes bails at complex types, resulting in nevers.

In the inverse plugin, both uses are typed. Perhaps that’s of interest: rehypejs/rehype-remark@35fda3e. Could you check if that type, inverted, works here too?

@remcohaszing
Copy link
Member

I believe it was related to the unified types. TypeScript 5 adds support for @overload, maybe that helps.

@smackesey
Copy link

Just ran into this issue and got confused, then a bit more confused reading this PR. @andrejpavlovic is your PR description right? I think HastRoot and MdastRoot should be switched in the "Current" and "Expected" sections?

Also is this PR moot in light of existing overload annotations that are either wrong or that typescript is choking on?

@wooorm
Copy link
Member

wooorm commented Sep 19, 2023

I checked again and it doesn’t seem possible for TS to understand the overloads yet.

I made sure that 99% of the use case of this plugin works:

remark-rehype/test.js

Lines 100 to 103 in b4799b5

const treeIn = unified().use(remarkParse).parse('hi')
const treeOut = await unified().use(remarkRehype).run(treeIn)
const doc = unified().use(rehypeStringify).stringify(treeOut)
assert.equal(doc, '<p>hi</p>')
.
I think that’s what you are trying to solve here: mdast -> hast.

For the other 1% of cases, I don’t know. But the solution would likely be in the space of fixing the unified types for use, if it can even be solved there, and otherwise for TS itself.

I’ll close this, I believe I did what you were looking for with https://github.com/remarkjs/remark-rehype/releases/tag/11.0.0. The trouble with overloads will have to be solved somewhere else!

@wooorm wooorm closed this Sep 19, 2023
@wooorm wooorm added the 💪 phase/solved Post is done label Sep 19, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants