Skip to content

Commit 26b1ab4

Browse files
committed
Use inclusive flag, as originally done, but include almost everything
1 parent 9761c3b commit 26b1ab4

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7664,7 +7664,7 @@ namespace ts {
76647664

76657665
function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, includeOuterFunctions: boolean) {
76667666
let key: string;
7667-
if (!reference.flowNode || assumeInitialized && (declaredType.flags & TypeFlags.NotNarrowable)) {
7667+
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
76687668
return declaredType;
76697669
}
76707670
const initialType = assumeInitialized ? declaredType : addNullableKind(declaredType, TypeFlags.Undefined);

src/compiler/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,12 +2219,9 @@ namespace ts {
22192219
UnionOrIntersection = Union | Intersection,
22202220
StructuredType = ObjectType | Union | Intersection,
22212221

2222-
// 'NotNarrowable' types are types where narrowing reverts to the original type, rather than actually narrow.
2223-
// This is never really correct - you can _always_ narrow to an intersection with that type, _but_ we keep
2224-
// Void as the only non-narrowable type, since it's a non-value type construct (representing a lack of a value)
2225-
// and, generally speaking, narrowing `void` should fail in some way, as it is nonsensical. (`void` narrowing
2226-
// to `void & T`, in a structural sense, is just narrowing to T, which we wouldn't allow under normal rules)
2227-
NotNarrowable = Void,
2222+
// 'Narrowable' types are types where narrowing actually narrows.
2223+
// This *should* be every type other than null, undefined, void, and never
2224+
Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | Boolean | ESSymbol,
22282225
/* @internal */
22292226
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
22302227
/* @internal */

0 commit comments

Comments
 (0)