Skip to content

Invalid type after destructuring a Record #56456

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

Closed
lcswillems opened this issue Nov 18, 2023 · 3 comments
Closed

Invalid type after destructuring a Record #56456

lcswillems opened this issue Nov 18, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@lcswillems
Copy link

πŸ”Ž Search Terms

record destructuring concat

πŸ•— Version & Regression Information

TypeScript 5.2

⏯ Playground Link

https://www.typescriptlang.org/play?ssl=5&ssc=1&pln=5&pc=57#code/MYewdgzgLgBAhgLhgJQKagE4BMA80MCWYA5gDTxgCeAfDALwwDe8SATOQEZIDMMAvgG4AUKEiwO9JjAB0suOQBebfsJHhoMSkjSZc+ImQo1JzRDHYwuMXoLViYCyQHkOAK3RRpcCBALEwABQu7sCe3r7+AYx85JQAlOTMSub8cQJAA

πŸ’» Code

const a: Record<string, any> = { a: 2, b: 3 };
const b = { ...a, z: 2 };

const y: Record<string, any> = { a: 2, b: 3 };
const z = Object.assign(Object.assign({}, y), { z: 2 });

πŸ™ Actual behavior

b is of type { z: number}

πŸ™‚ Expected behavior

b should be of type:

Record<string, any> & {
    z: number;
}

Same as the type of z

Additional information about the issue

No response

@fatcerberus
Copy link

Duplicate of #27273. Also this is a spread, not a destructuring.

@fatcerberus
Copy link

Note that it’s not actually an β€œinvalid type” - { z: number } is a valid description of what you get, just not the most convenient.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Nov 20, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants