Closed
Description
openedon Jan 12, 2021
After #42149, which usually preserves the type aliases of unions as written, some type aliases end up de-aliased in control flow:
(example based on @types/amap-js-api
)
type Direction = 'up' | 'down' | 'left' | 'right'
interface Input {
direction?: Direction
}
declare let input: Input
if (input.direction) {
input.direction/*should be Direction*/
}
Expected: The inner input.direction: Direction
Actual: The inner input.direction: 'up' | 'down' | 'left' | 'right'
This occurs because control flow narrowing uses filterType
, which doesn't understand type aliases or attempt to preserve them. Previously the union-interning behaviour preserved the alias, but that's no longer the case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment