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 a CLI for type checking #145

Open
remcohaszing opened this issue Feb 27, 2024 · 7 comments
Open

Add a CLI for type checking #145

remcohaszing opened this issue Feb 27, 2024 · 7 comments

Comments

@remcohaszing
Copy link
Member

remcohaszing commented Feb 27, 2024

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
Copy link

mrazauskas commented Mar 2, 2024

If only typechecks are need, you can use TSTyche:

  • it is a CLI tool, which wraps around TypeScript's APIs,
  • it uses currently installed TypeScript package by default,
  • it makes it very easy to select files for typechecking (no need too create projects),
  • the language service plugins are supported.

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
Copy link

karlhorky commented Mar 2, 2024

@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 mdx-js/mdx-analyzer#371 ?)

@mrazauskas
Copy link

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 [email protected]. 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
Copy link

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link

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.

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

3 participants