Skip to content

Incorrect Object is possibly 'null'. error inside Promise.prototype.then #13015

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
kimamula opened this issue Dec 19, 2016 · 1 comment · Fixed by #13487
Closed

Incorrect Object is possibly 'null'. error inside Promise.prototype.then #13015

kimamula opened this issue Dec 19, 2016 · 1 comment · Fixed by #13487
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@kimamula
Copy link
Contributor

kimamula commented Dec 19, 2016

TypeScript Version: 2.1.4 (2.2.0-dev.20161218 also)

Code

With --strictNullChecks,

interface Foo {
    prop: string;
}

function nullableFooPromise(): Promise<Foo | null> {
    return Promise.resolve(null);
}

nullableFooPromise()
  .then(nullableFoo => nullableFoo ? nullableFoo : { prop: 'foo' })
  .then(foo => console.log(foo.prop)); // this line raises an error

Expected behavior:
I expect this to compile (it does actually when I use [email protected]).

Actual behavior:
I get an error,
index.ts(11,28): error TS2531: Object is possibly 'null'.

@aluanhaddad
Copy link
Contributor

This looks to be related to #13008. The overloads for .then are not declared in the right order.

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 19, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 15, 2017
@mhegazy mhegazy added this to the TypeScript 2.3 milestone Feb 15, 2017
@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants