镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

2.1 breaks promise chaining #12886

Description

This (apparently valid) code compiled OK with TypeScript 2.0:

function f(): Promise<void> {
  return Promise.resolve(4).then((n: number) => {
    if (n !== 200) {
      return Promise.reject('error');
    }
    return Promise.resolve();
  });
}

With TypeScript 2.1.4 it gives:

test.ts(2,10): error TS2322: Type 'Promise' is not assignable to type 'Promise'.
Type 'number' is not assignable to type 'void'.

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es2015"]
  }
}

It seems that the problem comes when promises are chained. For instance when removing the .then() chain, compilation runs without any error:

function f(n: number): Promise<void> {
  if (n !== 200) {
    return Promise.reject('error');
  }
  return Promise.resolve();
}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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