Skip to content
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

Error with strictNullChecks when nested function #9345

Closed
horiuchi opened this issue Jun 24, 2016 · 2 comments
Closed

Error with strictNullChecks when nested function #9345

horiuchi opened this issue Jun 24, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@horiuchi
Copy link

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'.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 24, 2016

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

@horiuchi
Copy link
Author

OK, I understand 👍

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 24, 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