Closed
Description
TypeScript Version: 3.2.0-dev.20181117
EDIT: I just tested with TS 3.2.0-rc and it has this bug
Search Terms: true extends false
Code
I feel like I'm losing my mind here. Or maybe I'm tired because it's 3.34am. Maybe I need to take a break. Am I missing something obvious?
//OK
//Expected: "n"
//Actual: "n"
type no = true extends false ? "y" : "n";
type G<DataT extends { b : boolean }> = (
true extends DataT["b"]?
["Actual", "true extends", DataT["b"]] :
"Expected"
)
//Wat?
//Expected: "Expected"
//Actual: ["Actual", "true extends", false]
type g = G<{ b : false }>;
Expected behavior:
g
to be of type "Expected"
.
Intuitively,
DataT
is of type{ b : false }
DataT["b"]
is of typefalse
true extends false
should be...false
Actual behavior:
g
is of type ["Actual", "true extends", false]
Playground Link: Here
EDIT: I just tested and this is not a problem in TS 3.0.1
I'm not crazy, phew.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
AnyhowStep commentedon Nov 23, 2018
This has no problems in either TS 3.2 or TS 3.0.1
jack-williams commentedon Nov 23, 2018
I think this is happening because of #27470
In
G
the constraint ofDataT
is being pulled down in the access expressionDataT["b"]
. So it is not thattrue extends false
, rather it is eagerly using the base constraint inDataT
so you gettrue extends boolean
. This is not covered by the fix #27490 because"b"
is not a generic type. You can see the correct behaviour if you defer the check using a parameter.or even doing:
AnyhowStep commentedon Nov 23, 2018
Yikes. I hope this is fixed. This breaks a lot of my code that was working in 3.0.1.
Using your workaround would make the type declarations even more verbose and complex =(
Thank you for looking into it! I had this gnawing at me even as I tried to sleep.
I guess I'll hold off on upgrading TS for now :x
Jessidhia commentedon Nov 27, 2018
This might be related to some problems I found while working on the React types; proving that
'x' extends keyof T
is not sufficient to let you indexT
with'x'
.ahejlsberg commentedon Nov 28, 2018
Simplified repro with expected outcomes:
Currently
Foo
is eagerly evaluated to"yes"
so every outcome is"yes"
.AnyhowStep commentedon Nov 29, 2018
Thank you for fixing this so quickly!
I just updated from
3.0.1
to3.3.0-dev.20181129
and nothing broke!2 remaining items