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

createSuccessObserverResult should also take a generic error #161

Closed
Xample opened this issue Feb 27, 2024 · 3 comments
Closed

createSuccessObserverResult should also take a generic error #161

Xample opened this issue Feb 27, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Xample
Copy link

Xample commented Feb 27, 2024

Which @ngneat/query-* package(s) are relevant/releated to the feature request?

query

Description

I'm having this abstract method:

    abstract getStuff$( ): ObservableQueryResult<Result, Error>;
    abstract getStuff$( ): ObservableQueryResult<Result, Error>;

I would like to implement it this way :

    getStuff$() {
        return of(createSuccessObserverResult({ key: "value" }));
    }

But I cannot because createSuccessObserverResult has the following signature:

export declare function createSuccessObserverResult<T>(data: T): QueryObserverResult<T>;

While I would need

export declare function createSuccessObserverResult<T, Error = DefaultError>(data: T): QueryObserverResult<T, Error>;

In order to comply with my abstract method.

Proposed solution

Just expose the Error in the util @ngneat\query\lib\utils.d.ts :

export declare function createSuccessObserverResult<T, Error = DefaultError>(data: T): QueryObserverResult<T, Error>;
export declare function createPendingObserverResult<T = unknown, Error = DefaultError>(): QueryObserverResult<T, Error>;

Alternatives considered

The workaround is to force typing the return :

createSuccessObserverResult<T>(data) as QueryObserverResult<T, Error>;

Do you want to create a pull request?

No

@Xample
Copy link
Author

Xample commented Feb 27, 2024

query/src/lib/utils.ts

@netanel-utila
Copy link

You are welcome to create a PR

@NetanelBasal NetanelBasal added enhancement New feature or request good first issue Good for newcomers labels Feb 28, 2024
@NetanelBasal
Copy link
Member

Fixed in #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants