Skip to content

Repo: Switch from explicit-function-return-type to isolatedDeclarations and/or explicit-module-boundary-type #9419

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

Closed
JoshuaKGoldberg opened this issue Jun 24, 2024 · 8 comments · Fixed by #10193
Labels
locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs team assigned A member of the typescript-eslint team should work on this.

Comments

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jun 24, 2024

Suggestion

Forking out of #8173 (comment):

@JoshuaKGoldberg: ... we keep the @typescript-eslint/explicit-function-return-type rule enabled.

@bradzacher: We could probably relax that.
I'd be okay with us doing isolatedDeclarations instead of EFRT.

I'd be in favor of moving to a lighter-weight enforcement of function return types internally. My understanding of the context is that we've traditionally enforced function return types for these reasons:

  • To be explicit in types as a stylistic point - holding over from when this was much more common, years ago
  • Type performance: since we're a non-trivial sized repo, it saves time in TypeScript type checking
  • Type stability: i.e. what TypeScript 5.5's isolatedDeclarations enforces

Now that isolatedDeclarations are stable, it seems reasonable to me that we'd switch our internal linting to only enforcing what it requires. We'd get the type performance and stability, without the more heavy-handed stylistic requirements. Our non-exported functions would now be able to have inferred return types! What does the team think?

Note that this is only for the internal linting of this repository. This issue doesn't impact end-users of typescript-eslint.

💖

@JoshuaKGoldberg JoshuaKGoldberg added triage Waiting for team members to take a look repo maintenance things to do with maintenance of the repo, and not with code/docs labels Jun 24, 2024
@Josh-Cena
Copy link
Member

Josh-Cena commented Jun 25, 2024

I always thought this rule is just for stylistic reasons. Otherwise (if you just care about declaration stability) why would you not use explicit-module-boundary-type instead?

@JoshuaKGoldberg JoshuaKGoldberg added team assigned A member of the typescript-eslint team should work on this. and removed triage Waiting for team members to take a look labels Jun 25, 2024
@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Jul 8, 2024

Same question as @Josh-Cena. Also I personally very much like the stylistic preference of always enforcing return types, but no strong opinion.

@JoshuaKGoldberg
Copy link
Member Author

I would be happy with explicit-module-boundary-type. Just as long as I don't have to keep annotating return types in all functions, always.

@JoshuaKGoldberg JoshuaKGoldberg changed the title Repo: Switch from explicit-function-return-type to isolatedDeclarations Repo: Switch from explicit-function-return-type to isolatedDeclarations and/or explicit-module-boundary-type Jul 8, 2024
@bradzacher
Copy link
Member

I always thought this rule is just for stylistic reasons

The big reason EFRT has remained is because it makes it easier to review PRs in github alone.

But TBH we're getting to a point of scale where most changes are pretty complicated and reviewing them in GH alone is hard.
Which is why I'm not able to review as much as I once did - most of my time is spent on mobile and it's impossible to review our PRs like that.

Additionally the place where EFRT shines is complex cross-boundary interactions where a change can cause unseen side-effects downstream somewhere. But almost all of our code is isolated and used within a single file - so you just don't have the same opportunity for actions-at-a-distance.

I think we're at this point where EFRT gets in the way more than it helps us. But I'm personally very strongly in favour of strictly typed module boundaries - so I don't think going to nothing at all is correct. Which leads us to EMBT or ID.

Realistically - ideally we should deprecate and remove EMBT now that isolatedDeclarations exists. The two systems look to implement the same things - though EMBT is actually much, much weaker of a check than what ID is. I don't really see a reason why all EMBT users couldn't migrate to ID.

The added benefit of ID is that you can switch ypur build over to oxc/swc/etc on top as well for that sweet sweet build speed improvement. Which I'm sure we would love too for a faster devloop and CI time.

@JoshuaKGoldberg
Copy link
Member Author

JoshuaKGoldberg commented Jul 8, 2024

Proposal: let's switch the repo to EMBT in the meantime, and file a followup issue each for deprecating EFRT and EMBT? Even if we decline either or both of those deprecations, IMO it'd be good to discuss separately.

@bradzacher
Copy link
Member

and file a followup issue each for deprecating EFRT

To clarify:

EFRT is great and a completely useful style - just not one that I think has use for our project any longer. The rule should stay - people find value in it and there is no alternative.

EMBT is a great and useful style - but it's a weak subset of ID and realistically should be deprecated in favour of people just using ID.

@bradzacher
Copy link
Member

Also note that ID would be easy to migrate to.
There are typed codemods to do the migration.

But we never built any tools for EMBT.

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Jul 12, 2024

Having played around with ID a little bit - my experience was I don't think it's actually easy to migrate to, in general

  • it significantly restricts what types can lie on the module boundary.
  • it can't be used without declaration: true (note that our repo has specified declaration: false intentionally in some places).

(In my quick test in the typescript-eslint repo, we get no ID errors for the packages that currently specify declaration: true 🎉, but we get quite a few if we run it in eslint-plugin and eslint-plugin-internal)

Note that ID is also not actually a superset of EMBT, since it does allow inferred return types, as long as they're "simple" for computers to infer (as opposed to for humans to infer). (reference: go to the phrase "There are also certain expressions where the type is "trivial" to calculate." in the TS 5.5 blog)

Conclusion - I'd say if we turn off EFRT, I would significantly prefer using EMBT rather than trying to switch to ID.

(also will preemptively say -1 on deprecating EMBT or EFRT)

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Nov 4, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs team assigned A member of the typescript-eslint team should work on this.
Projects
None yet
4 participants