π Search Terms
array never filter
π Version & Regression Information
- This changed between versions 5.4.5 and 5.5.2
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.2#code/IYIwzgLgTsDGEAJYBthjAg4gUwHbagEtYBhVdBAbwCgEEAHKAewm3mwBMkndIoBXeEygAKevxDJiCAG7Bk-bAC4EfQrgDmASioBfavuoo0GEj1hRsrMiYTYAHq1wcMOfEVLkMNOrB59BCGEROQVlVWh1bSpaOlV+egIRAAMzXAsrcIASSlDFXWStAG5Y-UM-XkRsZGwAWzwIMBU3AmIbdABtAF0EAF4EDvwAdwQ0jOsvEQByYCmtLpKjf0QAM0JkVksOAFEa+txGvrs9hrAAOjWNpJFquoadXoA+Y7uDs4qAoSg+3v6xywmJmK1Gol02nF2r0aHQADF0znlsGcggBlSKaETAoA
π» Code
abstract class GenericClass {
protected constructor(public value: string) {}
}
class ConcreteClass extends GenericClass {
constructor(value: string) {
super(`Concrete: ${value}`);
}
}
const elements: GenericClass[] = [new ConcreteClass('a')];
const filteredElements = elements.filter((element) => element.constructor === ConcreteClass);
filteredElements[0].value.toString();
// ~~~~~
// Property 'value' does not exist on type 'never'.
π Actual behavior
The return type from the .filter() expression is never[]
π Expected behavior
The return type from the .filter() expression is GenericClass[]
Additional information about the issue
I searched through the open issues in the days since 5.5.2 were released but I could not find any which matched this case. Apologies if I missed anything. I've tried to reduce this down to the most minimal example that I can.
π Search Terms
array never filter
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.2#code/IYIwzgLgTsDGEAJYBthjAg4gUwHbagEtYBhVdBAbwCgEEAHKAewm3mwBMkndIoBXeEygAKevxDJiCAG7Bk-bAC4EfQrgDmASioBfavuoo0GEj1hRsrMiYTYAHq1wcMOfEVLkMNOrB59BCGEROQVlVWh1bSpaOlV+egIRAAMzXAsrcIASSlDFXWStAG5Y-UM-XkRsZGwAWzwIMBU3AmIbdABtAF0EAF4EDvwAdwQ0jOsvEQByYCmtLpKjf0QAM0JkVksOAFEa+txGvrs9hrAAOjWNpJFquoadXoA+Y7uDs4qAoSg+3v6xywmJmK1Gol02nF2r0aHQADF0znlsGcggBlSKaETAoA
π» Code
π Actual behavior
The return type from the
.filter()expression isnever[]π Expected behavior
The return type from the
.filter()expression isGenericClass[]Additional information about the issue
I searched through the open issues in the days since 5.5.2 were released but I could not find any which matched this case. Apologies if I missed anything. I've tried to reduce this down to the most minimal example that I can.