Skip to content

strictNullChecks and "This condition will always return..." #34770

Closed
@lukaszprus

Description

@lukaszprus

TypeScript Version: 3.6.3

Search Terms:

strictNullChecks

Code

const a = (x: number): number => {
  if (x === null) {
    console.log(1);
  }

  if (x === 'grhrt') {
    console.log(1);
  }

  return x;
};

a(null);

Expected behavior:

With strictNullChecks option I would expect an error in line 2 similar to the one in line 6. Something of the form "This condition will always return 'false'... "

Actual behavior:

No error in line 2

Playground Link:

https://www.typescriptlang.org/play/index.html?noImplicitAny=false&strictFunctionTypes=false&strictPropertyInitialization=false&strictBindCallApply=false&noImplicitThis=false&noImplicitReturns=false&alwaysStrict=false&esModuleInterop=false&target=2&ssl=13&ssc=9&pln=1&pc=1#code/MYewdgzgLgBAhjAvDAFADwFwzAVwLYBGApgE4CUWuhpSAfDAN4CwAUDDAJYBmqaSiyXABshZRq3btQkEEKIA6ISADmKAIxkA3BJgBfVju69+yAOTKSACxJRTY5m0nSIshUtUbtj-Sx0kiUDgkYDBoXrperHAowqKaQA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions