Skip to content

Commit fc3e040

Browse files
committed
Revert "Merge pull request #7235 from weswigham/narrow-all-types"
This reverts commit ef0f6c8, reversing changes made to 9f087cb.
1 parent 7e00d7e commit fc3e040

14 files changed

+2
-409
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7662,7 +7662,7 @@ namespace ts {
76627662

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

Diff for: src/compiler/types.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -2218,13 +2218,7 @@ namespace ts {
22182218
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
22192219
UnionOrIntersection = Union | Intersection,
22202220
StructuredType = ObjectType | Union | Intersection,
2221-
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,
2221+
Narrowable = Any | ObjectType | Union | TypeParameter,
22282222
/* @internal */
22292223
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral,
22302224
/* @internal */

Diff for: tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.js

-38
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.symbols

-70
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.types

-76
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralType.js

-21
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralType.symbols

-32
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralType.types

-35
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.js

-21
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.symbols

-32
This file was deleted.

Diff for: tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.types

-35
This file was deleted.

0 commit comments

Comments
 (0)