allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
332 stars 29 forks source link

[Feature Request] Force include for library #60

Closed ronparkdev closed 10 months ago

ronparkdev commented 10 months ago

Hi,

I'm using your plugin well to increase strict code in a non-strict project. But I'm facing one problem

  1. overall strict is off
  2. files with // @ts-strict added using typescript-strict-plugin -> type catching
  3. Using a library from node_modules in a file with // @ts-strict -> library is not strict.

Of course, this is not the role of typescript-strict-plugin, so it's normal, But we can't just add // @ts-strict to a library in node_modules, can we?

So I thought about adding a config.forceInclude similar to config.exclude.

If it's included in config.forceInclude, it will be strict even if it doesn't have // @ts-strict.

Anyway, thanks for the library, I'm enjoying using it!

ronparkdev commented 10 months ago

To reproduce this issue,

  1. set strict off in tsconfig.json
  2. install typescript-strict-plugin
  3. install the yup library
  4. use yup in your documentation with // @ts-strict added
  5. in const params = await object({ id: string().required(), }).validate({}), the type of params should be { id: string }, but it is caught as { id?: string } because the library is not strict.

The solution is to do the above.

kamkry commented 10 months ago

I'm glad you're enjoying the library! Your idea is interesting, but unfortunately, as you've rightly pointed out, there are some limitations to the approach.

The TypeScript language service plugins operate with the files that are currently open in your editor, and don't have access to all the files in your project, especially those inside node_modules. It would be very resource-intensive to proccess every file in there, so it's unfortunately not possible right now.

Thank you for the idea though!