Skip to content

Declaring index signature based on property type gives invalid error #30982

Description

TypeScript Version: latest, demonstrable on playground (links below)

Search Terms: index signature diagnostics property type

Code:

interface BaseNode {
  kind: string;
  [key: string]: string | TokenNode["data"];
}

interface TokenNode extends BaseNode {
  kind: 'token';
  data: TokenData;
}

interface TokenData {
  offset: number;
  width: number;
  leading_width: number;
  trailing_width: number;
}

Expected behavior:

No errors, as the code is correct.

Actual behavior:

An error on interface TokenNode:

Interface 'TokenNode' incorrectly extends interface 'BaseNode'.
  Index signature is missing in type 'TokenNode'.

HOWEVER if I change TokenNode["data"] to its value TokenData, the error goes away.

Playground Link:

Code above displaying the error
Code above with the fix, no errors

Activity

  1. RyanCavanaugh commented on Apr 17, 2019

    @RyanCavanaugh
    Member

    Current behavior dates back to 2.1

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

    BugA bug in TypeScriptDomain: Indexed Access TypesThe issue relates to accessing subtypes via index access

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions