You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of this is fine. value satisfies ab and ac, so it satisfies the union, but it doesn't satisfy either strictly so it doesn't satisfy the union either. However the implementation is fragile and only just manages to get assert.isFalse(union.strictTest(value)) right. The last line assert.isFalse(intersection.strictTest(value)) fails and reveals the problem. When the union is inside an intersection, its children checkers for ab and ac pass the strict test for value.
which means that back in TUnion allowedProps becomes { 'a', 'b', 'c' } (confirmed by logging) after being populated by the checkers for both ab and ac.
However this doesn't happen if you check the union by itself. Since allowedProps is optional and has no default in TUnion.getChecker, it's just undefined, and each TIface makes its own separate set by default. But once the union is in an intersection, the intersection makes a new set which gets passed down and shared between the interfaces.
This is complicated so I haven't figured out how to solve it, but it seems that you would need to have multiple sets of allowed props and an interface would need to check that the properties fall within at least one of those sets. To put this example in concrete TS:
interfaceAB{a: number,b: number,}interfaceAC{a: number,c: number,}typeU=AB|ACinterfaceD{d: number}typeI=U&D// These work:consti: I={a: 1,b: 1,d: 1}consti: I={a: 1,c: 1,d: 1}// but this doesn't:consti: I={a: 1,b: 1,c: 1,d: 1}
The checkers for AB, AC, and D all need to know that {a, b, d} and {a, c, d} are the acceptable sets of properties.
The text was updated successfully, but these errors were encountered:
This test fails:
Most of this is fine.
value
satisfiesab
andac
, so it satisfies the union, but it doesn't satisfy either strictly so it doesn't satisfy the union either. However the implementation is fragile and only just manages to getassert.isFalse(union.strictTest(value))
right. The last lineassert.isFalse(intersection.strictTest(value))
fails and reveals the problem. When the union is inside an intersection, its children checkers forab
andac
pass the strict test forvalue
.This is related to #45.
What happens is that in these lines in
TUnion
:ts-interface-checker/lib/types.ts
Lines 174 to 175 in ac67d73
allowedProps
is passed toTIface
:ts-interface-checker/lib/types.ts
Lines 293 to 294 in ac67d73
which means that back in TUnion
allowedProps
becomes{ 'a', 'b', 'c' }
(confirmed by logging) after being populated by the checkers for bothab
andac
.However this doesn't happen if you check the union by itself. Since
allowedProps
is optional and has no default inTUnion.getChecker
, it's just undefined, and eachTIface
makes its own separate set by default. But once the union is in an intersection, the intersection makes a new set which gets passed down and shared between the interfaces.This is complicated so I haven't figured out how to solve it, but it seems that you would need to have multiple sets of allowed props and an interface would need to check that the properties fall within at least one of those sets. To put this example in concrete TS:
The checkers for AB, AC, and D all need to know that
{a, b, d}
and{a, c, d}
are the acceptable sets of properties.The text was updated successfully, but these errors were encountered: