Skip to content

TS 3.5 regression casting object to { [key: string]: unknown }; #31381

Closed
@mjbvz

Description

@mjbvz

TypeScript Version: 3.5.0-dev.20190507

Search Terms:

  • index signature
  • unknown

Code

export interface I { 
    foo(): { [key: string]: unknown };
}

export class B implements I {
    foo(): object {
        return {};
    }
}

Expected behavior:
This code compiles without errors in TS 3.4.5

Actual behavior:
In 3.5@next, there is the error:

Property 'foo' in type 'B' is not assignable to the same property in base type 'I'.
  Type '() => object' is not assignable to type '() => { [key: string]: unknown; }'.
    Type 'object' is not assignable to type '{ [key: string]: unknown; }'.
      Index signature is missing in type '{}'.

This may be by design but I'm not sure which issue tracks the change.

We hit this issue in the vscode codebase

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions