Skip to content

Possible 4.3 regression with generic function and rest in object destructuring Β #43941

Closed

Description

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • This changed between versions 4.2 and 4.3 beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Params = {
    foo: string;
} & ({ tag: 'a'; type: number } | { tag: 'b'; type: string });

const getType = <P extends Params>(params: P) => {
    const {
        // Omit
        foo,

        ...rest
    } = params;

    return rest;
};

declare const params: Params;

switch (params.tag) {
    case 'a': {
        // TS 4.2: number
        // TS 4.3: string | number
        const result = getType(params).type;

        break;
    }
    case 'b': {
        // TS 4.2: string
        // TS 4.3: string | number
        const result = getType(params).type;

        break;
    }
}

πŸ™ Actual behavior

4.3 behaviour should match 4.2 behaviour. See comments in code.

πŸ™‚ Expected behavior

See comments in code.

Activity

  1. OliverJAsh commented on May 27, 2021

    @OliverJAsh
    ContributorAuthor

    This is marked as fixed but the behaviour in 4.3.2 still differs from 4.2 as per my comment above. Is that expected?

  2. OliverJAsh commented on May 31, 2021

    @OliverJAsh
    ContributorAuthor

    Wesley Wigham (@weswigham) Not sure this issue has been fixed, should we re-open it?

  3. weswigham commented on Jun 1, 2021

    @weswigham
    Member

    It definitely looks fixed in the nightly playground... and in the associated PR's tests...

  4. OliverJAsh commented on Jun 2, 2021

    @OliverJAsh
    ContributorAuthor

    I had a look at the tests but I couldn't understand what behaviour they were trying to verify. Do we expect my example to behave the same in 4.3 as it did in 4.2, or is this an intended change? In my testing the behaviour in 4.3 and nightly differs from that of 4.2, as per my code comments.

  5. weswigham commented on Jun 2, 2021

    @weswigham
    Member

    I see the behavior match what you noted as the 4.2 behavior in the nightly playground?

  6. OliverJAsh commented on Jun 2, 2021

    @OliverJAsh
    ContributorAuthor

    Yes you're right, sorry!

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

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions