镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

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:

Activity

  1. ahejlsberg commented on May 14, 2019

    @ahejlsberg
    Member

    This is an intended effect of #30637. See rationale here.

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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