-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
function f(): void;
function f(x: string): string;
function f(x?: string): void | string {
if (x !== undefined) {
return x;
}
}
function g(): Promise<void>;
function g(x: string): Promise<string>;
async function g(x?: string): Promise<void | string> {
if (x !== undefined) {
return x;
}
}
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/no-invalid-void-type": "error"
}
}
tsconfig
Expected Result
No errors.
Actual Result
void is only valid as a return type or generic type variable. 3:25 - 3:29
void is only valid as a return type or generic type variable. 11:39 - 11:43
Additional Info
It's possible to work around the linter in the first example by changing the implementation return type from void | ...
to undefined | ...
, although this may require introducing an explicit return undefined
statement to the function body if the compiler option noImplicitReturns
is set.
In the second example, changing Promise<void | ...>
to Promise<undefined | ...>
is not possible because it introduces a compiler error
This overload signature is not compatible with its implementation signature. (2394)
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
5.39.0 |
@typescript-eslint/parser |
5.39.0 |
TypeScript |
4.8.4 |
ESLint |
8.15.0 |
node |
web |
jedwards1211 and dandv
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin