Skip to content

Promise-type checking gives false errors #2010

@iislucas

Description

@iislucas

The following code used to type-check fine (Using the types for Promises prior to: DefinitelyTyped/DefinitelyTyped@c95561b ), but since they now use types based on: https://github.com/Microsoft/TypeScript/blob/master/src/lib/es6.d.ts#L3542
the code produces false type errors.

/// <reference path='es6-promise.d.ts' />

interface T1 {
  __t1: string;
}

interface T2 {
  __t2: string;
}

interface T3 {
  __t3: string;
}

function f1() : Promise<T1> {
  return Promise.resolve({ __t1: "foo_t1" });
}

function f2(x:T1) : T2 {
  return { __t2: x.__t1 + ":foo_21" };
}

var x3 = f1()
  .then(f2, (e:Error) => {
    console.log("error 1");
    throw e;
  })
  .then((x:T2) => {
    return { __t3: x.__t2 + "bar" };
  });

It gives these errors (in TypeScript 1.4.1):

promise-oddity.ts(23,10):  error TS2453: 
The type argument for type parameter 'U' cannot be inferred from the usage. 
Consider specifying the type arguments explicitly.
  Type argument candidate 'T2' is not a valid type argument 
because it is not a supertype of candidate 'void'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions