Search Terms
predicate find force boolean
Suggestion
As per #5850 array.prototype.filter doesn't enforce boolean as a return type anymore. I want to propose the same behavior for wherever a predicate is needed. This means not only filter, but find, some, every and maybe others. These functions should not enforce boolean as return type of the predicate passed to them.
Use Cases
This will be useful wherever the developer is looking for a result that is not missing some value(s).
Examples
Say I want to find the first parkSpace that has position. This works in TypeScript 3.1.1:
this.selectedParkSpace = this.parkSpaces.filter(o => o.position)[0] || null;
but this doesn't:
this.selectedParkSpace = this.parkSpaces.find(o => o.position) || null;
For the latter, TypeScript complains:
Type 'undefined' is not assignable to type 'boolean'.
Checklist
My suggestion meets these guidelines:
Search Terms
predicate find force boolean
Suggestion
As per #5850
array.prototype.filterdoesn't enforcebooleanas a return type anymore. I want to propose the same behavior for wherever a predicate is needed. This means not onlyfilter, butfind,some,everyand maybe others. These functions should not enforce boolean as return type of the predicate passed to them.Use Cases
This will be useful wherever the developer is looking for a result that is not missing some value(s).
Examples
Say I want to find the first
parkSpacethat hasposition. This works in TypeScript 3.1.1:this.selectedParkSpace = this.parkSpaces.filter(o => o.position)[0] || null;but this doesn't:
this.selectedParkSpace = this.parkSpaces.find(o => o.position) || null;For the latter, TypeScript complains:
Checklist
My suggestion meets these guidelines: