Skip to content

Recursive type with index signature issues spurious error #1889

Closed
@NoelAbrahams

Description

@NoelAbrahams

Hi,

TS:1.4

The compiler issues an error on property bar below:

   interface Foo {
        [x: string]: number|Foo;
   }

   interface Bar extends Foo {

        /* Error: Property 'bar' of type '{ num: number; }' 
        is not assignable to string index type 'number | Foo'. */
        bar: { num: number };
    }

My understanding of this is "any type that extends Foo is permitted to have a property that is either a number or an object that is indexable by string to produce a number or..(and so on) ".

The latter case is clearly true for {num: number} and yet the compiler issues an error.

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