Skip to content

Type narrowing doesn't work with mutable variables in closures #23776

Description

Includes arguments.

TypeScript Version: 2.9.0-dev.201xxxxx

Search Terms:

Code

declare const a: {} | void;
if (a instanceof Object) a; // {}
if (a instanceof Object) () => a; // {}
declare let b: {} | void;
if (b instanceof Object) b; // {}
if (b instanceof Object) () => b;

Expected behavior:

if (b instanceof Object) () => b; // {}

Actual behavior:

if (b instanceof Object) () => b; // void | {}

Playground Link:

Related Issues:

Activity

  1. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Seems like it also breaks colorization.

  2. ghost added
    DuplicateAn existing issue was already created
    on Apr 30, 2018
  3. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Indeed.

    On the colorization, the last return keyword is white, should be blue.

        if (process instanceof Coroutine) return this.register(
          name,
          {
            init: state => state,
            main: (param, state) =>
              (process as Coroutine<R, R, P>)[Coroutine.port].send(param)
                .then<Supervisor.Process.Result<R, S>>(({ value: reply, done }) =>
                  done
                    ? void this.kill(name, undefined) ||
                      (process as Coroutine<R, R, P>).then<Supervisor.Process.Result<R, S>>(reply =>
                        [reply, state])
                    : [reply, state,]),
            exit: reason => void process[Coroutine.terminator](reason),
          },
          state,
          reason);
        return super.register(name, process, state);

    https://github.com/falsandtru/spica/blob/v0.0.167/src/supervisor.es2018.ts#L29

  4. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Hm, I'm using VSCode v1.22.2 on Win10.

  5. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Dark (Visual Studio).

  6. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor
  7. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    This is my screenshot.

    image

  8. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Looks like the error is only present in vscode non-insiders without the latest grammar installed.

    I see, I wait for the next release. Currently, this is not a serious problem for me.

  9. falsandtru commented on Apr 30, 2018

    @falsandtru
    ContributorAuthor

    Resolved, thanks for letting me know!

  10. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions