Skip to content

2.4 errors for missing index signature with object literal spread #16694

Closed
@Pajn

Description

@Pajn

TypeScript Version: 2.4.0

Code

import {CSSProperties} from 'glamorous'

export const a = (): CSSProperties => ({})

export const b = ({withA = false}): CSSProperties => ({
  ...withA ? a() : undefined,
})

Expected behavior:
No errors

Actual behavior:
TypeScript displays this error:

error TS2322: Type '{} | { [propertyName: string]: string | number | CSSProperties | undefined; alignContent?: "cente...' is
not assignable to type 'CSSProperties'.
  Type '{}' is not assignable to type 'CSSProperties'.
    Index signature is missing in type '{}'

The code works fine in 2.3.4 which is what I would expect. I return an object literal, there is nothing that should prevent it to be assigned to a more open type.
Without the tenery at the spread position the code gives no errors.

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