specta-rs / tauri-specta

Completely typesafe Tauri commands
MIT License
368 stars 40 forks source link

Remove unused TAURI_CHANNEL import #129

Closed bgschiller closed 1 month ago

bgschiller commented 1 month ago

Depending on your tsconfig, unused imports may be compilation errors.

oscartbeaumont commented 1 month ago

This import is actively used when exporting Tauri Channels.

You can probably use header to configure your linter to ignore the bindings file as we can't possibly account for all edge cases in people's linting setups.

bgschiller commented 1 month ago

Thanks for taking a look!

Unfortunately, there's not a way to use header like you describe. Since this isn't a linter error, but a tsconfig option, it can't be turned off for a whole file: see https://stackoverflow.com/q/51385041 . The options are to add a line-comment, like // @ts-ignore, or to turn it off for the whole project. I'd like to avoid turning off noUnusedLocals for my whole project, since I find it to be a valuable rule.

Another option would be to make the TS template smart enough to know which imports were necessary, and only include those ones.

Please let me know if either of these options would be acceptable to you. I'd be happy to write up another MR.

oscartbeaumont commented 1 month ago

What is the problem with using // @ts-ignore within the header? Really you should be able to trust us to get the types correct within that file.

We could make the template smart enough to know the used imports but it would also add a heap of complexity which would be nice to avoid if we can.

Alternatively you could also move noUnusedLocals to a regular linter Eg. Biome, Eslint, etc if you also have that for more comprehensive linting.

bgschiller commented 1 month ago

What is the problem with using // @ts-ignore within the header?

@ts-ignore applies only to the next line of code; not the whole file.

It does look like I can do // @ts-nocheck and turn off type errors for the whole file though, so that's a workable solution for me. Thanks for talking it through with me :)