禁止在返回类型或者泛型类型之外使用void。
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-invalid-void-type": "error"
}
} export type NoOp = () => void;
export function noop(): void {
console.info('noop');
}
export const trulyUndefined = void Number.MAX_VALUE;
export async function promiseMeSomething(): Promise<void> {
return Promise.reject('value').catch(() => {
console.error('error');
});
}
export type StillVoid = void | never; // 不允许使用void作为类型
export type PossibleValues = string | number | void;
// 不允许使用void作为类型
export type MorePossibleValues = string | (string | void);
// 不允许使用void作为类型
export function logSomething(thing: void) {
return thing;
}
export function printArg<T = void>(arg: T) {
return arg;
}
export interface Interface {
lambda: () => void;
// 不允许使用void作为类型
prop: void;
} 合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功