void is not valid as a constituent in a union type
14 *
15 * @returns void if command is called with no active text editor.
16 */
17export async function initPrintPython2(): Promise<void | string> {18 const editor = vscode.window.activeTextEditor;
19 if (!editor) {
20 return;
void is not valid as a constituent in a union type
8
9export async function executeCommand(
10 statement: string
11): Promise<string | void> {12 const editor = vscode.window.activeTextEditor;
13 if (!editor) {
14 return;
Description
Disallows usage of void type outside of return types or generic type arguments. If void is used as return type, it shouldn’t be a part of intersection/union type with most other types.
Bad Practice
type PossibleValues = string | number | void;
type MorePossibleValues = string | ((number & any) | (string | void));
function logSomething(thing: void) {}
function printArg<T = void>(arg: T) {}
logAndReturn<void>(undefined);
interface Interface {
lambda: () => void;
prop: void;
}
class MyClass {
private readonly propName: void;
}
Recommended
type NoOp = () => void;
function noop(): void {}
let trulyUndefined = void 0;
async function promiseMeSomething(): Promise<void> {}
type stillVoid = void | never;