Skip to content

Spread operator does not correctly infer from Record types #40955

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
fnimick opened this issue Oct 5, 2020 · 2 comments
Closed

Spread operator does not correctly infer from Record types #40955

fnimick opened this issue Oct 5, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@fnimick
Copy link

fnimick commented Oct 5, 2020

TypeScript Version: 4.0.2 (& nightly 4.1.0-dev.20201005)

Search Terms: spread operator, record type, infer / inference / inferred

Code

const first: Record<string, string> = { foo: 'bar' };

const second = { ...first, baz: '' };

const third = { ...second, qux: '' };

console.log(third.baz);
console.log(second.foo);

Expected behavior: second is of type Record<string, string> & { baz: string}; analogous to third which is inferred as type { baz: string, qux: string }.

Actual behavior: second is of type { baz: string } and reports an error accessing any other member.

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201005&ssl=1&ssc=12&pln=1&pc=36#code/MYewdgzgLgBAZgSwE7QFwwEoFNRICYA80SCYA5gDQzGlkB8MAvDAN7wgjoDkARgIZIuMAL4BuAFDjQkWBBzg8TVjAB0axCihV+AL25Cxk6dBhQAFskXM2alXOl4qARwCuAD30iJU8BBAAbLBV-EDIACnNLFV0ASgljAKCQ8PsFFTgOOPEgA

@andrewbranch
Copy link
Member

Duplicate of #27273

@andrewbranch andrewbranch marked this as a duplicate of #27273 Oct 6, 2020
@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Oct 6, 2020
@typescript-bot
Copy link
Collaborator

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

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

3 participants