🔎 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
abstractclassGenericClass{protectedconstructor(publicvalue: string){}}classConcreteClassextendsGenericClass{constructor(value: string){super(`Concrete: ${value}`);}}constelements: GenericClass[]=[newConcreteClass('a')];constfilteredElements=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.