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

No contextual typing for interfaces that extends interface with index signature #3804

Description

@tinganho

I was hoping this could work:

class A {
    public a: string;
}

interface B {
    [index: string]: A;
}

interface C extends B {
    a;
    b;
    c;
}

let c: C;
c.a.a // c.a of type A

but members of interface C has type any instead I was hoping I could get type A?

Notice I don't want to define directly:

let c: B;

because I need to pass C as a type with defined props.

Activity

  1. changed the title [-]No contextual typings for interfaces that extends interface with index signature[/-] [+]No contextual typing for interfaces that extends interface with index signature[/+] on Jul 10, 2015
  2. RyanCavanaugh commented on Jul 10, 2015

    @RyanCavanaugh
    Member

    Contextual typing applies to expressions, not declarations, so that part isn't exactly relevant.

    It's legal to declare members of type any (which is what you've done) even when you have an index signature. I don't think we would take a breaking change here.

  3. tinganho commented on Jul 12, 2015

    @tinganho
    ContributorAuthor

    This is my problem right now:

    interface StyleRules extends Radium.StyleRules {
        feed: Radium.CSSStyleDeclaration;
        feedTitle: Radium.CSSStyleDeclaration;
        feedLoadMoreButton: Radium.CSSStyleDeclaration;
    .   ...
    }

    Having to repeat a type that I think could be inferred from a base interface. If not inferred maybe be able to reference the base signature value type?

  4. RyanCavanaugh commented on Jul 13, 2015

    @RyanCavanaugh
    Member
  5. tinganho commented on Jul 14, 2015

    @tinganho
    ContributorAuthor

    Yes sort of related. Though this suggestion is an interface derived from an
    interface/class. His suggestion where a class derived from a
    interface/class.

    tis 14 juli 2015 kl 00:45 skrev Ryan Cavanaugh notifications@github.com:

    #1373 #1373 ?

    —
    Reply to this email directly or view it on GitHub
    #3804 (comment)
    .

  6. locked and limited conversation to collaborators on Jun 19, 2018
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

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions