Skip to content

Cannot spread object literal into object with index signature #16373

@ajafff

Description

@ajafff

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions