Skip to content

Revert "Merge pull request #7235 from weswigham/narrow-all-types" #8946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7662,7 +7662,7 @@ namespace ts {

function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, includeOuterFunctions: boolean) {
let key: string;
if (!reference.flowNode || assumeInitialized && (declaredType.flags & TypeFlags.NotNarrowable)) {
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
return declaredType;
}
const initialType = assumeInitialized ? declaredType : addNullableKind(declaredType, TypeFlags.Undefined);
Expand Down
8 changes: 1 addition & 7 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2218,13 +2218,7 @@ namespace ts {
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
UnionOrIntersection = Union | Intersection,
StructuredType = ObjectType | Union | Intersection,

// 'NotNarrowable' types are types where narrowing reverts to the original type, rather than actually narrow.
// This is never really correct - you can _always_ narrow to an intersection with that type, _but_ we keep
// Void as the only non-narrowable type, since it's a non-value type construct (representing a lack of a value)
// and, generally speaking, narrowing `void` should fail in some way, as it is nonsensical. (`void` narrowing
// to `void & T`, in a structural sense, is just narrowing to T, which we wouldn't allow under normal rules)
NotNarrowable = Void,
Narrowable = Any | ObjectType | Union | TypeParameter,
/* @internal */
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral,
/* @internal */
Expand Down
38 changes: 0 additions & 38 deletions tests/baselines/reference/typeGuardNarrowsPrimitiveIntersection.js

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions tests/baselines/reference/typeGuardNarrowsToLiteralType.js

This file was deleted.

32 changes: 0 additions & 32 deletions tests/baselines/reference/typeGuardNarrowsToLiteralType.symbols

This file was deleted.

35 changes: 0 additions & 35 deletions tests/baselines/reference/typeGuardNarrowsToLiteralType.types

This file was deleted.

21 changes: 0 additions & 21 deletions tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.js

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions tests/baselines/reference/typeGuardNarrowsToLiteralTypeUnion.types

This file was deleted.

Loading