Skip to content

Conversation

@NicoFraenzel
Copy link
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

This PR adds two more overloads to the remarkRetext function to fix the TypeScript type definitions (see issue #18). One without any parameters and another with a common signature (as the compiler doesn't generate one without the @overload tag).

New overloads:

/**
 * ...
 *
 * @overload
 * @returns {TransformMutate}
 *
 * ...
 *
 * @overload
 * @param {Parser | Processor} [destination]
 *   Parser or processor (required).
 * @param {Options | null | undefined} [options]
 *   Configuration (optional).
 * @returns {TransformBridge | TransformMutate}
 *   Transform.
 *
 * ...
 */

Resulting type definitions:

export default function remarkRetext(): TransformMutate;
export default function remarkRetext(processor: Processor, options?: Options | null | undefined): TransformBridge;
export default function remarkRetext(parser: Parser, options?: Options | null | undefined): TransformMutate;
export default function remarkRetext(destination?: import("unified").Processor<import("nlcst").Root, undefined, undefined, undefined, undefined> | Parser | undefined, options?: Options | null | undefined): TransformBridge | TransformMutate;

This removes the need for @ts-expect-error in test.js and dependent projects.

@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 Apr 1, 2025
@codecov
Copy link

codecov bot commented Apr 1, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Member

@JounQin JounQin left a comment

Choose a reason for hiding this comment

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

LGTM

@NicoFraenzel
Copy link
Contributor Author

Sorry, my bad. Got confused there for a moment. New type definitions:

export default function remarkRetext(processor: Processor, options?: Options | null | undefined): TransformBridge;
export default function remarkRetext(parser: Parser, options?: Options | null | undefined): TransformMutate;
export default function remarkRetext(destination: Parser | Processor, options?: Options | null | undefined): TransformBridge | TransformMutate;

@wooorm
Copy link
Member

wooorm commented Apr 2, 2025

I was applying this patch in rehype-remark, and confirmed:

const x = rehypeRemark(unified())
const y = rehypeRemark()
const p = Math.random() > 0.5 ? unified() : undefined
const z = rehypeRemark(p)

Before:

x: TransformBridge
y: TransformMutate
z: TransformBridge & TransformMutate // Note sure *why* TS decides this, but this is the problematic part

After:

x: TransformBridge
y: TransformMutate
z: TransformBridge | TransformMutate // Good

wooorm added a commit to rehypejs/rehype-remark that referenced this pull request Apr 2, 2025
@wooorm wooorm merged commit 24bfc81 into remarkjs:main Apr 2, 2025
4 checks passed
@github-actions

This comment has been minimized.

@wooorm wooorm added ☂️ area/types This affects typings 💪 phase/solved Post is done labels Apr 2, 2025
@wooorm
Copy link
Member

wooorm commented Apr 2, 2025

thanks, released in 6.0.1!

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Apr 2, 2025
wooorm added a commit to remarkjs/remark-rehype that referenced this pull request Apr 2, 2025
wooorm added a commit to rehypejs/rehype-retext that referenced this pull request Apr 2, 2025
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

Development

Successfully merging this pull request may close these issues.

3 participants