Closed
Description
π Search Terms
This binary expression is never nullish
π Version & Regression Information
- (Pretty confident that) this changed in commit or PR Disallow truthiness/nullishness checks on syntax that never varies on itΒ #59217
β― Playground Link
π» Code
const sets = undefined
// try granular part of day first
?? group[partOfDay]
// then check if the granular part of day is any part of nighttime, and if so try all night spawns
?? (PartOfDay.AllNighttime & partOfDay ? group[PartOfDay.AllNighttime] : undefined)
// then check if the granular part of day is any part of daytime, and if so try all day spawns
?? (PartOfDay.AllDaytime & partOfDay ? group[PartOfDay.AllDaytime] : undefined)
// fallback to all day spawns
?? group[PartOfDay.Always];
π Actual behavior
My codebases have a number of instances of things similar to the above β undefined
is used to put the actual potential results each on their own line, all formatted the same way. However this no longer works in TS 5.6.0 due to it throwing an error. I think this is an over-eager error message.
π Expected behavior
I should be able to format the code how I want to still
Additional information about the issue
Other examples of code in my codebases broken by this
let plugs: PlugRaw[] = undefined
?? (this.state ? refresh.plugs ?? [] : undefined)
?? this.plugs?.slice()
?? (!this.plugSetHash ? undefined : (await DestinyPlugSetDefinition.get(this.plugSetHash))?.reusablePlugItems)
?? (this.plugSetHash ? undefined : (await DeepsightSocketExtendedDefinition.get(this.item?.definition.hash))?.sockets[this.index]?.rewardPlugItems)
?? [];
Component.create()
.classes.add(ItemTooltipSourceClasses.ActivityName)
.text.set(undefined
?? Display.name(lostSectorDisplay)
?? Display.name(source.dropTable.displayProperties)
?? Display.name(activity))
.appendTo(activityComponent);
.setRefreshMethod(() => undefined
?? (status === UiStatusType.Cut ? this.human?.getStatusLevel(StatusType.Bleeding) === BleedLevel.Minor : undefined)
?? (status === StatusType.Bleeding ? this.human?.getStatusLevel(StatusType.Bleeding) === BleedLevel.Major : undefined)
?? !!this.human?.hasStatus(status as StatusType))
Also, this still works for true &&
conditions and false ||
conditions β would be nice if it stayed consistent:
const inRange = true
&& gatherTile.x - treasureRange <= treasure.x && gatherTile.x + treasureRange >= treasure.x
&& gatherTile.y - treasureRange <= treasure.y && gatherTile.y + treasureRange >= treasure.y
&& executor.z === map.position.z;
const needsAuthView = false
|| (viewRequiredAuth === "required" && !ProfileManager.isAuthenticated())
|| (viewRequiredAuth === "spy" && !ProfileManager.get());