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

Unable to compile TypeScript file that imports the module due to missing/ incorrect type #23

Closed
motss opened this issue Jan 7, 2022 · 5 comments

Comments

@motss
Copy link

motss commented Jan 7, 2022

Problem

This is the error message when compiling TypeScript file that imports the module.

error TS2315: Type 'Visitor' is not generic.

9 export type Visitor = import('unist-util-visit').Visitor<Node>;

Reduced test case

This is a reduced test case written in TypeScript

import rehypePrism from 'rehype-prism-plus';
import rehypeStringify from 'rehype-stringify';
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { unified } from 'unified';
import type { VFile } from 'vfile';

export async function mdParse(value: string): Promise<VFile> {
  return unified()
    // remark
    .use(remarkParse)
    .use(remarkGfm)
    .use(remarkRehype)
    // rehype
    .use(rehypePrism)
    .use(rehypeStringify)
    .process(value);
}

Expected behavior

TypeScript file that imports the module should compile successfully without any typing issue

Actual behavior

TypeScript file fails to compile due to missing/ incorrect type

Other information

  1. TypeScript: 4.5.4
  2. vite: 2.7.2
  3. vue-tsc: 0.30.2
  4. rehype-prism-plus: 1.1.3
@timlrx
Copy link
Owner

timlrx commented Jan 8, 2022

I replicated the code with all the latest versions of the dependencies and typescript 4.5.4 and have no issue.

I got a feeling that there is some kind of module resolution problem going on. Can you try running npm ls unist-util-visit and see whether there are any dependencies on versions <3? Most of the google searches for error TS2315 suggest deleting node_modules, package-lock.json and installing again.

@motss
Copy link
Author

motss commented Jan 8, 2022

@timlrx Tested again with the suggestion in your previous comment but still having the same problem.

AFAIK it is not a TypeScript problem. Please try this repo and it is easily reproducible.

@timlrx
Copy link
Owner

timlrx commented Jan 8, 2022

I removed that line and published a new package. It should work now.

@motss
Copy link
Author

motss commented Jan 8, 2022

@timlrx I think you haven't published a new version because that line was removed after v1.2.0.

@timlrx
Copy link
Owner

timlrx commented Jan 9, 2022

It was published on npm. Also published the release on Github now.

@timlrx timlrx closed this as completed Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants