-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue