Skip to content

Fix using remark in typescript directly#513

Merged
wooorm merged 2 commits intoremarkjs:mainfrom
remcohaszing:fix-remark-export-type
Jul 24, 2020
Merged

Fix using remark in typescript directly#513
wooorm merged 2 commits intoremarkjs:mainfrom
remcohaszing:fix-remark-export-type

Conversation

@remcohaszing
Copy link
Copy Markdown
Member

Remark exports a unified processor, not a function that returns a processor. Unified processors also happen to be functions returning a new processor, meaning the old type worked for most situations, but not all.

@remcohaszing remcohaszing added ☂️ area/types This affects typings 👶 semver/patch This is a backwards-compatible fix labels Jul 18, 2020
Copy link
Copy Markdown
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

This works for direct calls to .parse and .stringify 👍

One consideration:

import remark = require("remark")

remark.use()

would be marked as valid in this typing, but results in:

Error: Cannot invoke `use` on a frozen processor.
Create a new processor first, by invoking it: use `processor()` instead of `processor`.

@remcohaszing
Copy link
Copy Markdown
Member Author

Perhaps we should create a new type in unified: FrozenProcessor.

FrozenProcessor would be what Processor is now, except the use method is omitted. Processor would inherit from FrozenProcessor and define use. remark would then export a FrozenProcessor instance.

@ChristianMurphy
Copy link
Copy Markdown
Member

That could work 👍

/cc @Rokt33r who implemented much of Processor, thoughts on having a FrozenProcessor?

@wooorm
Copy link
Copy Markdown
Member

wooorm commented Jul 23, 2020

/cc @remcohaszing FrozenProcessor now released in unified. Does that mean you can now update this PR based on that?

Remark exports a unified processor, not a function that returns a processor.
Unified processors also happen to be functions returning a new processor.
This requires a minimum unified version of 9.1.0.
@remcohaszing
Copy link
Copy Markdown
Member Author

Updated to use FrozenProcessor. I also had to rebase.

Copy link
Copy Markdown
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @remcohaszing! 🙇

@wooorm wooorm changed the title Fix the export type for remark Add support for using remark in ts directly Jul 24, 2020
@wooorm wooorm changed the title Add support for using remark in ts directly Fix using remark in typescript directly Jul 24, 2020
@wooorm wooorm merged commit fbbc3a9 into remarkjs:main Jul 24, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Jul 24, 2020
@Rokt33r
Copy link
Copy Markdown
Member

Rokt33r commented Jul 28, 2020

/cc @Rokt33r who implemented much of Processor, thoughts on having a FrozenProcessor?

@ChristianMurphy I think it looks good for now. Sorry for my late answer

@wooorm wooorm added the 💪 phase/solved Post is done label Aug 4, 2021
@remcohaszing remcohaszing deleted the fix-remark-export-type branch November 23, 2021 13:41
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 👶 semver/patch This is a backwards-compatible fix

Development

Successfully merging this pull request may close these issues.

4 participants