Skip to content

Type Guards no longer work inside a nested closure. #8552

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

Closed
david-driscoll opened this issue May 11, 2016 · 2 comments
Closed

Type Guards no longer work inside a nested closure. #8552

david-driscoll opened this issue May 11, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@david-driscoll
Copy link

TypeScript Version:
nightly (1.9.0-dev.20160217)

Code

interface TypeGuard {
  guard: boolean;
}
function isTypeGuard(value: any): value is TypeGuard {
  return value.guard;
}

let a: { notGuard: boolean } | TypeGuard;
if (isTypeGuard(a)) {
  const b: TypeGuard = a;
  let c: TypeGuard
  (() => c = a)();
}

Expected behavior:
The guarded type should be guarded within any nested closures.

Actual behavior:
The guarded type is not guarded in any nested closures. This has previously been working correctly.

Example outputs...

image

image

This is impacting ReactiveX/rxjs#1697

cc @alexeagle

@malibuzios
Copy link

Related: #7719, #7739, #8367, #8541

I believe this has been described as a breaking change in #7662

@david-driscoll
Copy link
Author

Alright makes sense for a major rev. Thanks!

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 11, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants