Skip to content

Spurious 'Index signature is missing in type' error when subclassing #1887

Closed
@NoelAbrahams

Description

@NoelAbrahams

Hi,

TS: 1.4

Not sure that I agree we should have an error here:

interface Indexer {
        [x: string]: number
}

class Base {

 foo() : Indexer {
    return undefined;
 }
}

/*Error: Class 'Foo' incorrectly extends base class 'Base'.
 Types of property 'foo' are incompatible.
 Type '() => { id: number; }' is not assignable to type '() => Indexer'.
 Type '{ id: number; }' is not assignable to type 'Indexer'.
 Index signature is missing in type '{ id: number; }'.
*/  
class Foo extends Base {

 foo() {
    return { id: 10 };
 }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions