Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

New no-invalid-void rule #4732

Closed
timocov opened this issue May 20, 2019 · 0 comments · Fixed by #4736
Closed

New no-invalid-void rule #4732

timocov opened this issue May 20, 2019 · 0 comments · Fixed by #4736

Comments

@timocov
Copy link
Contributor

timocov commented May 20, 2019

Rule Suggestion

We've such rule internally and I believe it might be useful for someone else and we can provide such rule in TSLint.

Is your rule for a general problem or is it specific to your development style? For a general problem.

What does your suggested rule do?

Restrict invalid usage of void type. For example, as property type or in type enumerations. I believe the void type should be used as return type only and be alone (without any kind of intersection types - see examples below).

List several examples where your rule could be used

function func(): void {}

type NormalType = () => void;

interface Interface {
    lambda: () => void;
    voidProp: void;
              ~~~~ [void as non-return type is forbidden]
}

class ClassName {
    private readonly propName: void;
                               ~~~~ [void as non-return type is forbidden]
}

let letVoid: void;
             ~~~~ [void as non-return type is forbidden]

type VoidType = void;
                ~~~~ [void as non-return type is forbidden]

class OtherClassName {
    private propName: VoidType;
}

type UnionType = string | number;
type UnionType2 = string | number | void;
                                    ~~~~ [void as non-return type is forbidden]

type UnionType3 = string | (number & any | (string | void));
                                                     ~~~~ [void as non-return type is forbidden]

type IntersectionType = string & number & void;
                                          ~~~~ [void as non-return type is forbidden]
JoshuaKGoldberg pushed a commit that referenced this issue Jul 6, 2019
* [new-rule] Added new no-invalid-void rule

Fixes #4732

* [no-invalid-void] Fixed lint error

* [no-invalid-void] Changed copyright year

* [no-invalid-void] Removed unnecessary checking parent of the node

* [no-invalid-void] Fixed a long string

* [invalid-void] Renamed no-invalid-void rule to invalid-void

* [invalid-void] Added rationale

* [invalid-void] Changed failure string

* [invalid-void] Changed failedKinds type from Array to Set

* [invalid-void] Added new kinds to fail

* [invalid-void] Fixed build for TypeScript < 2.3

https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#generic-parameter-defaults

* [invalid-void] Replaced default generic type of WalkContext and AbstractWalker to undefined from {}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants