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
{{ message }}
Repository navigation
RegExpMatchArray has lost some compatibility with Array since 2.1.0-dev.20160729 #10041
Several subtle issues at play here. With #9407 we still perform subtype reduction for the operands of the || and ?: operators. However, even after subtype reduction the expression (''.match(/ /) || []) has type RegExpMatchArray | never[] because there are extra optional properties introduced by RegExpMatchArray. In the property access for the map property we would previously perform subtype reduction again, and that would reduce the union function type of map down to a single type. This step we now omit because of #9407.
I think the real issue here is that we produce the union type RegExpMatchArray | [] instead of just RegExpMatchArray (and this issue was there all along). It may be that for || and ?: we should say that if neither operand is a subtype of the other, but one is assignable to the other, we pick the type of the one to which the other is assignable.
Activity
RyanCavanaugh commentedon Jul 30, 2016
Same root cause as #10025 but it's much less clear how to fix this example
falsandtru commentedon Jul 30, 2016
I understand as a breaking change, not a bug. Thanks Ryan Cavanaugh (@RyanCavanaugh) .
ahejlsberg commentedon Jul 30, 2016
Several subtle issues at play here. With #9407 we still perform subtype reduction for the operands of the
||and?:operators. However, even after subtype reduction the expression(''.match(/ /) || [])has typeRegExpMatchArray | never[]because there are extra optional properties introduced byRegExpMatchArray. In the property access for themapproperty we would previously perform subtype reduction again, and that would reduce the union function type ofmapdown to a single type. This step we now omit because of #9407.I think the real issue here is that we produce the union type
RegExpMatchArray | []instead of justRegExpMatchArray(and this issue was there all along). It may be that for||and?:we should say that if neither operand is a subtype of the other, but one is assignable to the other, we pick the type of the one to which the other is assignable.falsandtru commentedon Jul 30, 2016
Thanks for the fix!