0
votes

I want to have stricter code checks and I don't want to be allowed to have any implicit 'any' types. Therefore I enabled "strict": true

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "strict": true
  },
  "include": ["./"]
}

If I write this function:

const testing = () => console.log("test");

VSCode auto infers the returning type by it's usage:

const testing: () => void

Is there any way I can make this stricter and not allow VSCode to auto infer?

thanks

1
Please, please, please, don't use es/ts lint rules that force all types to be specified (you can look those rules up). It is not a good idea. It actively makes TS development harder with little or no benefit. Inference is part of the way TS is meant to work, without it life would be a pain.Titian Cernicova-Dragomir
@TitianCernicova-Dragomir while I agree it makes development hard, it makes PR reviews easier when you work in a big team with people who does not know your area of the code very well. That said, we also do not use any lint rule for that 😁distante
@distante Yeah, I can see the point of that, but it's such a pain... I think this is a case for needing better tooling to show inferred types in the PRs, minion dollar idea right there, if anyone wants to pick it up :PTitian Cernicova-Dragomir
@TitianCernicova-Dragomir I completely agree. If PR's are a problem this change is not solving the core issue. You can check out the code in an editor and look at it at that point. There are some CR tools that integrate with editors you can directly look at a PR in it. I've not actually used this functionality but I know it exists.VLAZ
I strongly agree with @TitianCernicova-Dragomir. To drive the point home even harder, inferred types are often far stricter in practice. Ex: most people will annotate with string instead of "Success" | "Failure"Aluan Haddad

1 Answers