Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Rule request: no-implicit-null-return-types #356

Closed
JoshuaKGoldberg opened this issue Apr 6, 2017 · 1 comment
Closed

Rule request: no-implicit-null-return-types #356

JoshuaKGoldberg opened this issue Apr 6, 2017 · 1 comment
Labels
External Issues that should be addressed in other repositories. Requires Type Checker Must be implemented with a "typed" rule that uses a TypeScript program. Type: Rule Suggestion Adding a new rule that doesn't yet exist here or in TSLint core.
Milestone

Comments

@JoshuaKGoldberg
Copy link

For teams with a large code base, turning on --strictNullChecks can take a while. Having rules that do part of the work would help incrementally enabling it.

If a function may return null or undefined, its return type should reflect this.

Bad:

class Person {
    private name;
    public setName(name: string) {
        this.name = name;
    }
    public getName(): string { // Might be undefined!
        return this.name;
    }
}

Better:

class Person {
    private name;
    public setName(name: string) {
        this.name = name;
    }
    public getName(): string | undefined {
        return this.name;
    }
}
@JoshuaKGoldberg JoshuaKGoldberg added Requires Type Checker Must be implemented with a "typed" rule that uses a TypeScript program. Status: Accepting PRs Difficulty: Medium People with non-trivial experience in TSLint should be able to send a pull request for this issue. Type: Rule Suggestion Adding a new rule that doesn't yet exist here or in TSLint core. labels Jul 6, 2018
@JoshuaKGoldberg
Copy link
Author

This is grander in scale than what a linter can do well. Addressing this would need access to the TypeScript language service.

I've started work on this in TypeStat instead.

@JoshuaKGoldberg JoshuaKGoldberg added External Issues that should be addressed in other repositories. and removed Difficulty: Medium People with non-trivial experience in TSLint should be able to send a pull request for this issue. Status: Accepting PRs labels Dec 26, 2018
@IllusionMH IllusionMH added this to the 6.1.0-beta milestone Feb 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Issues that should be addressed in other repositories. Requires Type Checker Must be implemented with a "typed" rule that uses a TypeScript program. Type: Rule Suggestion Adding a new rule that doesn't yet exist here or in TSLint core.
Projects
None yet
Development

No branches or pull requests

2 participants