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

Add missing dependency for types #675

Merged

Conversation

Methuselah96
Copy link
Contributor

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

Added dependencies on @types/prop-types and mdast-util-to-hast since they are used in the built declaration files and produce type errors without them:

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

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 62:23-35
TS7016: Could not find a declaration file for module 'prop-types'. '/home/runner/work/ParagonCore/ParagonCore/.yarn/cache/prop-types-npm-15.8.1-17c71ee7ee-c056d3f1c0.zip/node_modules/prop-types/index.js' implicitly has an 'any' type.
  If the 'prop-types' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/prop-types'
    60 | }
    61 | import {uriTransformer} from './uri-transformer.js'
  > 62 | import PropTypes from 'prop-types'
       |                       ^^^^^^^^^^^^
    63 |

@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 13, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 13, 2022

Codecov Report

Merging #675 (91ad6e9) into main (bd8e53b) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #675   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          731       731           
=========================================
  Hits           731       731           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd8e53b...91ad6e9. Read the comment docs.

package.json Outdated
"@types/unist": "^2.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-whitespace": "^2.0.0",
"mdast-util-to-hast": "^12.0.0",
Copy link
Member

@wooorm wooorm Mar 13, 2022

Choose a reason for hiding this comment

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

Suggested change
"mdast-util-to-hast": "^12.0.0",

Nice catch!
Could you solve the RemarkRehypeOptions by instead importing it from remark-rehype? That’s already a dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The source is correctly importing it from remark-rehype. I created microsoft/TypeScript#48242 since it seems like a TypeScript bug.

Copy link
Contributor Author

@Methuselah96 Methuselah96 Mar 14, 2022

Choose a reason for hiding this comment

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

I've narrowed this PR to just add @types/prop-types for now. Hopefully the dependency on mdast-util-to-hast can be fixed in upstream.

Copy link
Member

@wooorm wooorm Mar 14, 2022

Choose a reason for hiding this comment

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

can be fixed in upstream.

This sounds like a pnp problem. Not related to TS?
Or is TS “flatting” it when generated types from JS?

Copy link
Contributor Author

@Methuselah96 Methuselah96 Mar 14, 2022

Choose a reason for hiding this comment

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

The higher-level issue is relying on package hoisting. 99% of the time this isn't an issue because the file structure will look like:

node_modules
|-mdast-util-to-hast@^12.0.0
|-react-markdown
|-remark-rehype

If mdast-util-to-hast@^1.0.0 is added as a dependency it now looks like:

node_modules
|-mdast-util-to-hast@^1.0.0
|-react-markdown
|-remark-rehype
  |-mdast-util-to-hast@^12.0.0

And react-markdown no longer has access to the correct types.

Therefore the TypeScript bug is that it's rewriting import('remark-rehype').Options as import('mdast-util-to-hast/lib').Options when it shouldn't. This is a potential problem for any package manager, Yarn PnP is just making it painfully obvious that there's an issue.

It seems unlikely that someone would add a dependency on mdast-util-to-hast@^1.0.0, that's just the easiest example to give. The more common cause of conflict is having workspaces and one app depends on react-markdown@^8.0.0 and the other depends on react-markdown@^7.0.0 and now you start having problems like this.

@Methuselah96 Methuselah96 force-pushed the add-dependencies-on-more-type-packages branch from e85fbce to 91ad6e9 Compare March 14, 2022 00:46
@Methuselah96 Methuselah96 changed the title Add dependencies on type packages declaration files depend on Add dependency on @types/prop-types Mar 14, 2022
@wooorm wooorm changed the title Add dependency on @types/prop-types Add missing dependency for types Mar 14, 2022
@wooorm wooorm merged commit c23ecf6 into remarkjs:main Mar 14, 2022
@github-actions

This comment has been minimized.

@wooorm wooorm added 📦 area/deps This affects dependencies ☂️ area/types This affects typings 💪 phase/solved Post is done labels Mar 14, 2022
@wooorm
Copy link
Member

wooorm commented Mar 14, 2022

Thanks, released!

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Mar 14, 2022
@Methuselah96 Methuselah96 deleted the add-dependencies-on-more-type-packages branch March 14, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 area/deps This affects dependencies ☂️ area/types This affects typings 💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

3 participants