Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OliverJAsh opened this issue May 4, 2021 · 6 comments Β· Fixed by #44081
Closed

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

OliverJAsh opened this issue May 4, 2021 · 6 comments Β· Fixed by #44081
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@OliverJAsh
Copy link
Contributor

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.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 6, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.1 milestone May 6, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label May 13, 2021
@OliverJAsh
Copy link
Contributor Author

OliverJAsh commented May 27, 2021

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?

@OliverJAsh
Copy link
Contributor Author

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

@weswigham
Copy link
Member

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

@OliverJAsh
Copy link
Contributor Author

OliverJAsh commented Jun 2, 2021

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.

@weswigham
Copy link
Member

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

@OliverJAsh
Copy link
Contributor Author

Yes you're right, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants