Skip to content

Breaking change interpreting jquery promise types #22362

Closed

Description

TypeScript Version: 2.8.0-dev.20180302

Code

/// <reference types="jquery" /> // version 3.3.0
const t: JQuery.Promise2<string, Error, number, boolean, any, any> = {} as any;
$.when(t).then((a, b) => {
    const s: string = b; //should fail!
});

Expected behavior:

Error: b is boolean.

Actual behavior:

No error: b is any.

Has expected behavior in 2.8.0-dev.20180301, but behavior changed in 2.8.0-dev.20180302.
There are some additional error locations on DefinitelyTyped -- just run dtslint --installAll (to ensure you're using typescript@next), then dtslint types jquery. (The errors don't reproduce with just tsc because they come from // $ExpectType assertions.)

Activity

  1. RyanCavanaugh commented on Mar 20, 2018

    @RyanCavanaugh
    Member

    Andy (Andrewkraft) (@Andy-MS) can you get to the root of this and see if it's something we need to fix on our side before 2.8 goes out?

  2. Repository owner unassigned on Mar 20, 2018
  3. RyanCavanaugh commented on Mar 20, 2018

    @RyanCavanaugh
    Member

    Confirmed regression 2.7 -> 2.8. Worked in all prior releases

  4. sandersn commented on Mar 20, 2018

    @sandersn
    Member

    Specifically, here is the breaking change, added at the very top of inferFromTypes.

    if (source.flags & TypeFlags.Any) {
        // We are inferring from an 'any' type. We want to infer this type for every type parameter
        // referenced in the target type, so we record it as the propagation type and infer from the
        // target to itself. Then, as we find candidates we substitute the propagation type.
        const savePropagationType = propagationType;
        propagationType = source;
        inferFromTypes(target, target);
        propagationType = savePropagationType;
        return;
    }

    This propagationType is then used in place of the current source when it is available. This adds 'any' for all type parameter found in the structure of the target type.

  5. locked and limited conversation to collaborators on Jul 25, 2018
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