Disallow truthiness coercions on known-true/known-false values · Issue #9041 · microsoft/TypeScript (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@RyanCavanaugh

Description

@RyanCavanaugh

Inspired by #7746 but making a new issue for clarity

Bad code:

function func(): boolean { return Math.random() > 0.5; } if (func) { // oops, meant to write func() }

Change: Under --strictNullChecks, it becomes an error to use an expression in a truthiness position unless the type of the expression is possibly-falsy

Possibly-falsy types are:

A truthiness position is: