#If function returns true, parameter is not null?

4 messages · Page 1 of 1 (latest)

lyric sun
#

How do I tell typescript that if a function returns true, parameter is not null?

e.g.

function biggerThanThree(x?: str) {
return str?.length > 3;
}

How to type this so that it knows that when biggerThanThree is true, x cannot be null.

steady crater
#

!hb type predicates

cunning stumpBOT
lyric sun
#

Thank you!! It was on the tip of my tongue, and I couldn't think what it was called!