Skip to content

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

Closed
@kimamula

Description

@kimamula

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions