-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
index operator and object spread #17849
Comments
@ahejlsberg, should this work with respect to changes made in #7029? |
|
This works as expected now |
This is an old issue but was never actually fixed? You can paste the original code into the playground and all the same errors occur. |
@RyanCavanaugh type A = { [key: string]: string };
var obj = { foo: 'foo', bar: 'bar', baz: 'baz'};
const {...rest} = obj;
const mapped: { [a in keyof typeof rest]: string } = rest;
var ok: A = obj;
var ok2: A = {...rest};
var ok3: A = mapped
var error: A = rest; // An error occurred |
TypeScript Version: 2.4.2
Code
Expected behavior:
The
obj3
assignment in test three should work without an issue.test4
in test four should be of typenumber
Actual behavior:
The
obj3
assignment in test three throws an error:Index signature is missing in type '{ b: number; c: number; }'.
test4
is of typeany
.It looks like when you use the spread operator, typescript changes the type of the index operator to return
any
.The text was updated successfully, but these errors were encountered: