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 TypeScript bug by adding workaround #676

Merged
merged 1 commit into from Mar 31, 2022

Conversation

Methuselah96
Copy link
Contributor

@Methuselah96 Methuselah96 commented Mar 14, 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

Follow-up to #675. Adds | undefined as suggested in microsoft/TypeScript#48242 (comment).

Fixes this build error:

ERROR in ../../.yarn/__virtual__/react-markdown-virtual-1089d10e66/0/cache/react-markdown-npm-8.0.0-3d725f3756-61412ecd18.zip/node_modules/react-markdown/lib/react-markdown.d.ts 47:32-56
TS2307: Cannot find module 'mdast-util-to-hast/lib' or its corresponding type declarations.
    45 |   remarkPlugins?: import('unified').PluggableList | undefined
    46 |   rehypePlugins?: import('unified').PluggableList | undefined
  > 47 |   remarkRehypeOptions?: import('mdast-util-to-hast/lib').Options | undefined
       |                                ^^^^^^^^^^^^^^^^^^^^^^^^
    48 | }
    49 | export type LayoutOptions = {
    50 |   className?: string | undefined

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

wooorm commented Mar 15, 2022

This goes against the idea of using TS through JSDoc, to solve an issue where TypeScript does not support PnP.
I’d rather use JSDoc as intended, where possible, and have TypeScript solve its issues, instead of applying unexplainable patches?

Related-to: syntax-tree/mdast-util-gfm#1 (comment).

@wooorm
Copy link
Member

wooorm commented Mar 30, 2022

Any thoughts on my comment? I’m leaning on seeing this as an issue TS should solve.

@Methuselah96
Copy link
Contributor Author

Methuselah96 commented Mar 30, 2022

Would you be open to adding | undefined instead as suggested in microsoft/TypeScript#48242 (comment)?

@wooorm
Copy link
Member

wooorm commented Mar 30, 2022

Where would that have to be added? Because the error line includes that undefined already.

Also it sounds kinda weird that adding undefined somewhere "fixes" an issue, and that both behaviors are expected.

@Methuselah96
Copy link
Contributor Author

Methuselah96 commented Mar 30, 2022

It would be added here:

-  * @property {import('remark-rehype').Options} [remarkRehypeOptions={}]
+  * @property {import('remark-rehype').Options | undefined} [remarkRehypeOptions={}]

@wooorm
Copy link
Member

wooorm commented Mar 30, 2022

Oh I’m up for an explicit undefined, sure 👍, but I’d say report back that it’s really weird that you have to this one weird trick to get completely unrelated behavior 🤷‍♂️

This is required for TypeScript to avoid referencing the wrong type (see microsoft/TypeScript#48242 (comment)).
@Methuselah96 Methuselah96 changed the title Move PluginOptions to avoid reference to mdast-util-to-hast Fix type emitted in declaration file Mar 30, 2022
@Methuselah96
Copy link
Contributor Author

PR updated. I agree, feel free to add a comment to microsoft/TypeScript#48242. I haven't gotten a response to my last two comments.

@wooorm wooorm changed the title Fix type emitted in declaration file Fix TypeScript bug by adding workaround Mar 31, 2022
@wooorm wooorm merged commit 704c3c6 into remarkjs:main Mar 31, 2022
@wooorm wooorm added 🐛 type/bug This is a problem ☂️ area/types This affects typings 💪 phase/solved Post is done labels Mar 31, 2022
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Mar 31, 2022
@Methuselah96 Methuselah96 deleted the fix-emitted-type branch March 31, 2022 14:26
@wooorm
Copy link
Member

wooorm commented Mar 31, 2022

Thanks, released! https://github.com/remarkjs/react-markdown/releases/tag/8.0.2

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/bug This is a problem
Development

Successfully merging this pull request may close these issues.

None yet

2 participants