Skip to content

Error with strictNullChecks when nested function #9345

Closed

Description

TypeScript Version:

Version 1.9.0-dev.20160624-1.0

Code

test.ts

function g(cb: () => Promise<boolean>): Promise<boolean> {
    return cb();
}
function f(a: string | null): Promise<boolean> {
    if (a === null) {
        return Promise.resolve(false);
    }
    return g(() => {
        console.log(a.substr(1));
        return Promise.resolve(true);
    });
}

execute the command tsc --target es2015 --module commonjs --strictNullChecks test.ts.

Expected behavior:

There is no compile error.

Actual behavior:

test.ts(9,21): error TS2531: Object is possibly 'null'.

Activity

  1. kitsonk commented on Jun 24, 2016

    @kitsonk
    Contributor

    Essentially duplicate of #9263 and #7662 as narrowing is reset across function boundaries as explained in #7718 (comment).

  2. horiuchi commented on Jun 24, 2016

    @horiuchi
    Author

    OK, I understand 👍

  3. added
    Duplicate
    on Jun 24, 2016
  4. locked and limited conversation to collaborators on Jun 19, 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

    Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions