Skip to content

TS2345 or TS2322 with generics when in multiple modules #8806

Closed
@Delagen

Description

@Delagen

TypeScript Version:

1.8.10

Code

node_modules/module1/test.example.ts

import {
    Observable
} from "rxjs";

export class ExampleServiceInstance<T> {
    private dataObservable: Observable<T>;

    constructor(data: () => Observable<T>) {
        this.dataObservable = data();
    }

    get data(): Observable<T> {
        return this.dataObservable;
    }

    reset(): Observable<T> {
        return this.dataObservable;
    }
}

app/test.ts

import {
    Observable,
} from "rxjs";

import {ExampleServiceInstance} from "module1/test.example";

declare type ExampleData = Object[];

class ExampleService {
    private service: ExampleServiceInstance<ExampleData>;

    constructor() {
        this.service = new ExampleServiceInstance<ExampleData>(()=>Observable.of(<ExampleData> []));
    }

    get data(): Observable<ExampleData> {
        return this.service.data;
    }

    load(): Observable<ExampleData> {
        return this.service.reset();
    }
}

Expected behavior:
NO TS errors

Actual behavior:

test.ts
(13,58): error TS2345: Argument of type '() => Observable<Object[]>' is not assignable to parameter of type '() => Observable<Object[]>'.
Type 'Observable<Object[]>' is not assignable to type 'Observable<Object[]>'.
Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'.
(17,10): error TS2322: Type 'Observable<Object[]>' is not assignable to type 'Observable<Object[]>'.
Property 'source' is protected but type 'Observable' is not a class derived from 'Observable'.
(21,10): error TS2322: Type 'Observable<Object[]>' is not assignable to type 'Observable<Object[]>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions