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

Object spreading a Record<string, any> gives wrong type #30538

Closed
golopot opened this issue Mar 22, 2019 · 2 comments
Closed

Object spreading a Record<string, any> gives wrong type #30538

golopot opened this issue Mar 22, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@golopot
Copy link

golopot commented Mar 22, 2019

TypeScript Version: 3.4.0-dev.20190322

Search Terms:
object spread, Record, index signature

Code

const fn = (a: Record<string, any>) => {
  const obj = { p: 1, ...a };

  obj.foo; // ts-error: Property 'foo' does not exist on type '{ p: number; }'
};

const fn2 = (a: { [_: string]: any }) => {
  const obj = { p: 1, ...a };

  obj.foo; // ts-error: Property 'foo' does not exist on type '{ p: number; }'
};

Expected behavior:

obj has type {p: number} & Record<string, any>.

This matches how typescript handles Object.assign.

Actual behavior:

Type of object-spreaded thing is ignored.

Playground Link:

link

Related Issues:

@ajafff
Copy link
Contributor

ajafff commented Mar 22, 2019

This is a duplicate of #27273

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 26, 2019
@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

4 participants