Sitelet https://web.archive.org/web/20241212123405/https://github.com/microsoft/TypeScript/issues/11920
Skip to content

disallow comparing to null and undefined unless they are valid cases in strict null mode #11920

Open
@zpdDG4gta8XKpMCd

Description

the rationale is the same as for --noUnusedLocals which in this case would be --noUselessNullChecks (i am not proposing a new flag, the existing --strictNullChecks flag should be used, this is for illustration only)

declare const value: number;
if (value !== null) { // <-- somehow valid, expected to be invalid, since number doesn't have null as a possible value
}
if (value !== '') { // <-- invalid as expected 
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions