typescript-eslint: `@typescript-eslint/explicit-function-return-type` does not work in .js files, need preset config for JS files
Before You File a Proposal Please Confirm You Have Done The Following…
- I have searched for related issues and found none that match my proposal.
- I have read the FAQ and my problem is not listed.
Description
@typescript-eslint/explicit-function-return-type is not a “type-checked” rule but could belong to the disableTypeChecked config since it does not make sense to require a return type in a context where types are not checked / mandatory, e.g. in .js files.
Impacted Configurations
disableTypeChecked config
Additional Info
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (15 by maintainers)
@bradzacher, even myself who created this issue don’t see the need anymore. Moreover in the latest versions of eslint / typescript-eslint, existing shared configs don’t raise any error.
I don’t think that’s a good summary, no. Many of our rules work just fine in JS files! Type-aware rules work just fine in JS files - so long as you’re declaring half-decent JSDoc types they’ll all work as expected. It’s just that JS files are often lazily typed (if at all) and the rules do essentially function on “garbage in, garbage out”.
IIRC there’s only three rules which will explicitly not work in a JS file:
explicit-function-return-typeexplicit-module-boundary-typesparameter-propertiesEverything else will work just fine (and the TS-specific stuff just never matches).
There could be some value in having a config to disable the above 3 rules as in “disable-requiring-type-syntax” or something? That way you could declare like
Hi @bradzacher, I refined the description.
Hi, not being able to find this issue, I unknowingly created a duplicate - so maybe this is some community reaction after all? 😄
My usecase is exactly as @bradzacher described - I have a fully TS type-aware codebase with a few config files (like
eslint.config.js, but also other.config.jsfiles for example) that are pure JS and I don’t really want to bother with typing them with jsdoc and looking for@typespackages for them… But there are a lot of useful rules in typescript-eslint that I’d keep if I had the option… (see here for my example of a usecase)With the new project service, it became easy to just use the default project with them and not bother configuring them totally separately, which is great. However, this makes some rules fail on them (it seems to me like with project service I don’t even need to disable type-aware rules at all?), like
explicit-module-boundary-types, which I really like to use. To add to it, I can’t even do something likebecause of how ES spreading works - I think I could just add 2 configs, but that’s a little bit confusing to us not that familiar with the new flat configs…
So I’d like to ask to reconsider the
disable-things-that-wont-work-in-pure-js-filesconfig because that’s exactly the solution I independently came up with when opening #9888…Should we have a config like
no-typescript-syntax-configthat turns off all rules that add or modify TypeScript syntax…?If you’re using the recommended config - then
disable-type-checkedis all you need 🙂It’s only when people branch out into custom configs that they need more! For those custom usecases we do have it documented to some degree (docs that likely need updating 😅):
also, lol on the eslint.config.js being the culprit 😆