Repository navigation
Remove TS no-use-before-define rule - #55806
noahtallen wants to merge 1 commit into
Conversation
|
Link to Calypso live: https://calypso.live?image=registry.a8c.com/calypso/app:build-13673 |
|
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
|
Makes a lot of sense to me. Thanks for removing it! |
|
The rule actually prevents a runtime error from happening, like: const a = () => b(2);
console.log( a() );
const b = ( x: number ) => x * 3;TypeScript compiles this without any warning, but at runtime it fails: If you used Because the warning seems trivial to fix by just reordering the definitions, and because the JS version of |
|
Ah, that's really unfortunate. I agree, if this is the only way to catch that error, we need to keep the rule. I do wonder if there is a smarter way to do the rule, because I'd guess most of our react code is written to avoid execution before functions are defined. (E.g. most everything happens after calling a function when everything has been defined, not as part of the script's initial execution) I noticed it when working in files already breaking the rule. So I guess those will need to be refactored. I'll close this since we can't just remove it altogether |
If you really want to use a convention where the "main" function is written at the beginning of the module, and the helper functions it calls are defined after it, you can always declare them with the |
Changes proposed in this Pull Request
While working on some TypeScript files in #32930, I noticed that I was unable to commit due to the "no-use-before-define" typescript-eslint rule. I propose we remove this rule, as I don't see a benefit to it.
It prevents this sort of pattern, where a helper component is defined after the main component:
In my opinion, that is a bit too picky. :) Plus, in TypeScript, if a definition for a variable isn't found, compilation should fail. I think that is a better way to handle problems with variables not existing.
I also found this, but I think it is for a different rule (no use before declare)
Testing instructions
CI should pass.