Skip to content

Types of property 'xxx' are incompatible #978

@ruslanmogilevskiy

Description

@ruslanmogilevskiy

I`m switching from TS 0.9.5 to 1.1 CTP and have this simplified .d.ts:

interface FooArray<T> extends Foo<T[]> {
    subscribeTo(transform?: (val: any) => T): FooArray<T>;
}
interface Foo<T> {
    subscribeTo(transform?: (val: any) => T): Foo<T>;
}

Compilation has failed failed with:
error TS2429: Interface 'FooArray' incorrectly extends interface 'Foo<T[]>':
Types of property 'subscribeTo' are incompatible:
Type '(transform?: (val: any) => T) => Foo' is not assignable to type '(transform?: (val: any) => T[]) => Foo<T[]>':
Types of parameters 'transform' and 'transform' are incompatible:
Type '(val: any) => T' is not assignable to type '(val: any) => T[]':
Type 'T' is not assignable to type 'T[]':
Property 'length' is missing in type '{}'.

Note that the TS 0.9.5 compiles the below code while 1.0/1.1-CTP does not.

Questions:

  1. Shouldn't FooArray.subscribeTo should be treated as an overload and added to the FooArray`s contract? I.e. FooArray will have two subscribeTo methods.
  2. How to fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions