Belated tsc/lint discoveries

Posted: 13 October, 2020 Category: rough notes Tagged: eslinttslinttypescriptjavascripttsc

ASI and linting...

So ASI (Automatic semicolon injection) is the thing that allows you to write carefree js / ts code without semicolons...

But you run into issues with IIAFEs (Immediately invoked asynchronous function executions) written in the shorthand form: (async()=>{})(), because technically, that first ( could itself be the beginning of a function invocation. How is the poor lil just-in-time compiler supposed to know what you mean?! Well, it doesn't.

The above form basically has to become either ;(async()=>{}) or (async()=>{});, and good linters will slap you around accordingly. Handily enough while all this was happening for me, tsc was also complaining about my blatant omission of what to do with the returned promise, which, because I truly didn't care about it, I had very naughtily prefixed with void.

Well, turns out a void prefix is as good as semicolon, folks. It's as good as a flipping semicolon! Because it makes it abundantly clear that this is the start of a new invocation. So: void (async()=>{})(), et voila, we're back in the land of no semicolons!

But wait: now the good linting rules are offended again, because... why, the audacity of that void... handle your promises, woman!



I wasn't as aware of these as I should have been, but turns out:

  • in tsconfig, the exclude patterns are applied specifically to the includes, not everything in the project.
  • eslintrc will by default pick up all .js files, and then if it's a typescript project and tsconfig is present, THEN it will check the includes there. If the includes in tsconfig are a subset of the files eslint is concerned with, then:

    • there will be some "remainder" files not covered by your ts project, and eslint will complain rather vehemently about them / it will lead to errors.
    • I don't know how, but I ended up with the eslintrc.js file itself falling into this gap, and then had to explicitly ignore it (which, I understand shouldn't happen, but well - here we are).