volarjs / volar.js

💙🌊
https://volarjs.dev/
MIT License
981 stars 47 forks source link

Add a CLI for type checking #145

Open remcohaszing opened 7 months ago

remcohaszing commented 7 months ago

There are vue-tsc and @astrojs/check. I haven’t looked in depth, but these tools both appear to perform type checkign for Vue and Astro respectively.

There’s also user demand for a CLI to do type checking in MDX.

Now that projects are moving the TypeScript integrations to a plugin, they can integrate with each other. I don’t think it’s sufficient to have a CLI for each framework. We need to have one CLI that can perform type checking for multiple Volar based languages.

Even better would be if we can convince the TypeScript team to support plugins while running tsc out of the box.

Related issues

mrazauskas commented 7 months ago

If only typechecks are need, you can use TSTyche:

Current documentation speak only about type testing to avoid misunderstanding. Actually TSTyche is more versatile. Any file is first passed through type checker and issues are reported. It is not required to include any type testing assertions.

karlhorky commented 7 months ago

@mrazauskas sounds interesting, does this work out of the box with .mdx files? (including awareness of components passed to MDXProvider)

Or if it requires some kind of plugin, is this easy to set up? (maybe even with the mdx-analyzer TS language service plugin https://github.com/mdx-js/mdx-analyzer/pull/371 ?)

mrazauskas commented 7 months ago

It would need an option to pick up files with .mdx extension. That is easy to do. Currently only .ts and .js files can be selected. beta versions were picking up all files, but it was odd to type check .json if it was around. If there is a use case, I can quickly add an option instead of predefined list of extensions. You can install tstyche@1.0.0-beta.9. It does not have this limitation.

Otherwise all you need is language service plugins. I was trying out Svelte and Vue files. All worked. Did not know MDX has a plugin too. I will give a spin later today (or tomorrow).


There is a plan to add plugins to TSTyche with API similar to what Rollup has. Meaning that, a TSTyche plugin could provide configuration, select files for type check, alter TSConfig, if need provide language service plugins as well or even create a virtual file system. If that’s a common task, it should be easy to setup.

mrazauskas commented 7 months ago

Seems like it works.

Hard to say precise, because first of all @mdx-js/typescript-plugin is not published as an npm package. A build script in the repo simply emits it to node_modules and ships with the extension. The repo includes plugin as JS file, but it is not valid in Node.js environment (import and module.exports are mixed in the same file). So I had to copy minified code from the VSCode extension. I see that there is a checkMdx option, but it is not clear how to use it (code is minified).

Not sure I get how type check should work in MDX. TypeScript is mentioned in readme of the extension with broken link: "see the TypeScript section of the MDX language server documentation."

Also note that https://mdxjs.com does not have search (would help to find something about type checks). Hm.. No search? Hard to believe. I must be blind ;D

remcohaszing commented 7 months ago

TSTyche looks cool, and it’s awesome it already supports plugins. However, it looks a bit out of scope. It does more than just type checking.

Ideally I want to aim for support in tsc, as this is an interface users are already familiar with.

remcohaszing commented 7 months ago

Hard to say precise, because first of all @mdx-js/typescript-plugin is not published as an npm package.

This still needs a bit of work before it’s published to npm.

mrazauskas commented 7 months ago

I agree. TSTyche is a type testing tool. Also installing plugins one by one and adding them to TSConfig is rather clumsy for type checking. There is no need to change this in TSTyche, of course.

Don’t get me wrong, I like the idea of having a type checker, but that is not tsc. It has its own tasks, just like tsserver binary. There could be separate a package like tscheck or so.

tsc works with projects. Its scope is a project. In TSTyche the scope is a single file. I think type checker should be able to check single files, like code editors or TSTyche does. For example, tscheck *.mdx.