Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2345 or TS2322 with generics when in multiple modules #8806

Closed
Delagen opened this issue May 25, 2016 · 7 comments
Closed

TS2345 or TS2322 with generics when in multiple modules #8806

Delagen opened this issue May 25, 2016 · 7 comments
Labels
Duplicate An existing issue was already created

Comments

@Delagen
Copy link

Delagen commented May 25, 2016

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[]>'.

@mhegazy
Copy link
Contributor

mhegazy commented May 25, 2016

looks like the same issue in #6496.

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 25, 2016
@Delagen
Copy link
Author

Delagen commented May 26, 2016

I think something not. No multiple declarations, no d.ts files at all

@Delagen
Copy link
Author

Delagen commented May 26, 2016

Even rxjs module is resolved to the same in both files

@mhegazy
Copy link
Contributor

mhegazy commented May 26, 2016

I do not see how you would get this error if observable in both file resolve to the same declaration. can you share the otuput of tsc --traceResolution on this sample?

@Delagen
Copy link
Author

Delagen commented May 27, 2016

When I upgraded to 1.9.0-dev which support this option, and compile manually through tsc error is gone

@Delagen
Copy link
Author

Delagen commented May 27, 2016

Error when I using ts-loader in webpack with same options.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 1, 2016

looks like an issue for https://github.com/TypeStrong/ts-loader then.

@mhegazy mhegazy closed this as completed Jun 1, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants