aegir
aegir copied to clipboard
feat!: enable ts noImplicitReturns
As discussed offline, this feature helps avoid issues like https://github.com/libp2p/js-libp2p-tcp/issues/185
Just tried this out locally. Given this function:
function foo (n: number): string | undefined {
if (n > 10) {
return 'ok'
}
}
I get a ts build error:
error TS7030: Not all code paths return a value.
1 function foo (n: number): string | undefined {
to make the error go away I have to do:
function foo (n: number): string | undefined {
if (n > 10) {
return 'ok'
}
return undefined // <- add this line
}
Do we want this? Seems like it adds unnecessary boilerplate.
If instead we switch @typescript-eslint/explicit-function-return-type to 'error' in eslint-ipfs-config, building succeeds but linting fails, and all we have to do to appease the linter is add the return type, not the extra return undefined.
What do you think?
The ts config change in this PR doesn't seem to actually require return types either, only when there's a branch in the function in question that affects the return type.
The eslint rule OTOH is a little less forgiving and requires return types all the time, regardless of the function structure.
By which I mean this builds fine with noImplicitReturns: true but needs "@typescript-eslint/explicit-function-return-type": "error" to fail linting:
function foo () {
return 'hello'
}
See: https://github.com/ipfs/eslint-config-ipfs/pull/114
Closing in favor of https://github.com/ipfs/eslint-config-ipfs/pull/114, which will get dependency updated in aegir by dependabot.