Skip to content

Cannot spread object literal into object with index signature #16373

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
ajafff opened this issue Jun 8, 2017 · 3 comments
Closed

Cannot spread object literal into object with index signature #16373

ajafff opened this issue Jun 8, 2017 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Jun 8, 2017

TypeScript Version: nightly (2.4.0-dev.20170608)

Code

declare let compilerOptions: ts.CompilerOptions;
const options: ts.CompilerOptions = {
    ...compilerOptions,
    noEmit: true,
    noUnusedLocals: true,
    ...{noUnusedParameters: true}, // was originally ...(condition ? {noUnusedParameters: true} : undefined)
};

Expected behavior:
No error as with [email protected]

Actual behavior:

error TS2322: Type '{ noEmit: true; noUnusedLocals: true; allowJs?: boolean | undefined; allowSyntheticDefaultImports...' is not assignable to type 'CompilerOptions'.
  Type '{ noEmit: true; noUnusedLocals: true; allowJs?: boolean | undefined; allowSyntheticDefaultImports...' is not assignable to type 'CompilerOptions'.
    Index signature is missing in type '{ noEmit: true; noUnusedLocals: true; allowJs?: boolean | undefined; allowSyntheticDefaultImports...'.

To make this work, I need to assign the object literal to a variable with a type annotation containing an index signature.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 8, 2017
@mhegazy mhegazy added this to the TypeScript 2.5 milestone Jun 8, 2017
@sandersn
Copy link
Member

sandersn commented Aug 9, 2017

I can't get this to repro inside our own code. Can you try this again on typescript@next? I'll see if I can get a standalone repro that doesn't depend on ts.CompilerOptions.

@sandersn
Copy link
Member

sandersn commented Aug 9, 2017

Nope, standalone code (not depending on ts.CompilerOptions) doesn't repro either.

@ajafff
Copy link
Contributor Author

ajafff commented Aug 13, 2017

Seems to be "fixed" by #16525
Will open a new issue if this bug appears again after the handling of undefined in spread types changes.

@ajafff ajafff closed this as completed Aug 13, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Oct 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants