Mateusz Burzyński
Mateusz Burzyński
@iisaduan would it be possible for you to take a quick look at this?
Note that the title of this issue is a little bit misguided. Both of those types are inferred here internally. The fact that one of them was "named" was always...
Wider covariant inference gets picked over more narrow contravariant one
With removed redundant pieces ([TS playground](https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240822&ssl=32&ssc=2&pln=1&pc=1#code/CYUwxgNghgTiAEkoGdnwMIAsCWFjwG8AoeeAB1hADsAXALngAVLb4AfeKgVwggG4iAXyJFQSOImiomLGoRLlZDAOIwoVYMzisO3XgOGjw0CUmmr1m2fNIVt9eKpBQaFjVupzdPfkJFiTBDM0Jxc3K3sbRXsGPV9DAMpEAHsqZDkwHDwGLFxgASIIEAyuGHsPWhU4MLV3aw5wiq8ZSO9eeABeRCzgADo7TwKAeiH4EfgaTAQAIy4Ac3hgZJBkKgByOUwoMjJqeAB3bEmJnGQ6InHEiSKSss8mqudXWojPdkcXpvevtt8ifayCAAFGBSuVZABKKLjKBgGhcKAQKqWH4tTwKcYgAAeuzhIGAjxqKPqH2JrTRtAUoLutCaBVI1PBkS6jPusn6snpiDBbPsfDGo1RjRJoWeZLevz8QA)): ```ts declare class Child { parent: Parent | null; } declare class Parent { parent: GrandParent | null; } declare class GrandParent { parent:...
Same thing happens even if we make all of those classes nominal: [TS playground](https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240822#code/CYUwxgNghgTiAEkoGdnwMIAsCWFjwG8AoeeAB1hADsAXALngAVLb4AfeKgVwggG4S5GNgBuUGggD6ADwEBfIkVBI4iaKiYsahQRTi0GAcRhQqwZvu0duvAaTLCxE+DPmLl0VUg3HT5rTr2WkZw4r5mFtRWnDz8uo7iUrJECkrgngjeaMYgYSYRAcRBlgw2cfYJzq4p7umUiAD2VMjaYDh4DFi4wAJEECCtXDCWkQbwOXl+o9Hh-pbsmvPWsfAAvIjtwAB0elG9APT78IfwNJgIAEZcAObwwA0gyFQA5NqYUGRk1PAA7thnpxwyDoRBOHnq-UGwyi0xCuRos2mC0RAQ4SOWtkUP3aCAAFGAhiMtABKQLHI5QMA0LhQCAhKaoxZRQQnEDSL5UkDAOGTApLcb5OZRBbTQQE6G0aa9UjionzdaymFaHZaaWIQlKyx8ckChn8iYIwXomK8GpAA)
1. TS starts to compute `currentParent` in `while (currentParent)`, this has two antecedents 2. the first antecedent is the `let currentParent` declaration. Since the declared type is a union the...
@RyanCavanaugh shouldn't this really be classified as a bug if the CFA incorrectly drops one of the possible types? It's not that this isn't precise enough - it's plain incorrect....
This one is not beyond repair 😉 https://github.com/microsoft/TypeScript/pull/59772
Relates to https://github.com/microsoft/TypeScript/pull/15576 and https://github.com/microsoft/TypeScript/pull/43183 , only expressions in the element access expressions are subject to constraint-based narrowing (you'd like to narrow argument expressions here). We can find this comment...
Bisects to [this diff](https://github.com/microsoft/TypeScript/compare/b1c52c53cc6c8cf35b19accfc3e29916489c821e...fb88f027b015d95816e91f6b4f0e67dc57fa7a9f), so the change likely was introduced by https://github.com/microsoft/TypeScript/pull/57909