Skip to content

Regression on Promise Type Checking in Latest Insiders #15352

Closed

Description

@mjbvz

From: microsoft/vscode#25215

TypeScript Version: 2.3.1-insiders0420

Code

Using es2015.lib.d.ts:

function foo(x: Promise<boolean>) {}

foo(new Promise(() => true))

Expected behavior:
This compiles fine with TS 2.2.2 and with the older insiders 2.3.1 release.

Actual behavior:
With the current insiders, we get: message: 'Argument of type 'Promise<{}>' is not assignable to parameter of type 'Promise<boolean>'. Type '{}' is not assignable to type 'boolean'.'

This is causing upwards of 230 compiler errors in the vscode codebase

Possible related to #15104

Activity

  1. added
    VS Code Tracked
    on Apr 24, 2017
  2. mhegazy commented on Apr 24, 2017

    @mhegazy
    Contributor

    This is an intentional change to tighten the promise compatibility checking. in your call back, inference fails, and the result is {}; previously it was allowed to assign Promise<{}> to a Promise<boolean>, which is unsafe.

    See https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#covariance-in-callback-parameters for more details

  3. added
    Breaking Change
    on Apr 24, 2017
  4. mjbvz commented on Apr 24, 2017

    @mjbvz
    ContributorAuthor

    Thanks. This change seems to make sense even though it will be a little painful to update our codebase for it. It was not entirely clear to me why the code was compiling in ts 2.2.2 case when I looked at the types and thought more about the problem.

    // cc Benjamin Pasero (@bpasero)

  5. locked and limited conversation to collaborators on Jun 14, 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

    Breaking ChangeVS Code Tracked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions