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

fix(query): Add export to _CreateBaseQueryOptions type #157

Merged
merged 1 commit into from
Feb 6, 2024
Merged

fix(query): Add export to _CreateBaseQueryOptions type #157

merged 1 commit into from
Feb 6, 2024

Conversation

Arthie
Copy link
Contributor

@Arthie Arthie commented Feb 5, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

I'm migrating from v1 to v2 and encountered this error:
Return type of public method from exported class has or is using name '_CreateBaseQueryOptions' from external module "node_modules/@ngneat/query/lib/base-query" but cannot be named. ts(4053)
Typescript can't name the return type of 'queryOptions' function in a public class method.

Here is a code example:

@Injectable({ providedIn: 'root' })
export class ExampleClientService {
    private httpClient = inject(HttpClient);

    queryUser(id: string) {
//  ^? error: Return type of public method from exported class has or is using name '_CreateBaseQueryOptions' from external module "node_modules/@ngneat/query/lib/base-query" but cannot be named.ts(4053)
        return queryOptions({
            queryKey: ['USER', id] as const,
            queryFn: () => {
                return this.httpClient.get(`/user/${id}`);
            },
        });
    }
}

Issue Number: N/A

What is the new behavior?

No more typescript errors when using "queryOptions" function return type in a public class method.
Adding export to the _CreateBaseQueryOptions interface fixes the typescript error.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Copy link

stackblitz bot commented Feb 5, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@NetanelBasal
Copy link
Member

I'm wondering why it happens only to you

@Arthie
Copy link
Contributor Author

Arthie commented Feb 5, 2024

It's because of the typescript's declaration compiler option. I assume it enables stricter rules, since typescript wants to include an import to the '_CreateBaseQueryOptions' type for the generated .d.ts file.

"compilerOptions": {
    "declaration": true
  },

If I set declaration to 'false' I don't get the error.
Setting 'declaration' to false solves my issue. This PR can be closed unless you want to fix it for 'declaration' true as well.

@NetanelBasal
Copy link
Member

Why do you need declaration true in applications?

@Arthie
Copy link
Contributor Author

Arthie commented Feb 6, 2024

Correct, you don't need declaration true in applications. However, declaration:true is the default setting for angular libraries generated with nx in our monorepo. We might want to publish those libraries with .d.ts files, so multiple applications can use them.

@NetanelBasal NetanelBasal merged commit b699664 into ngneat:main Feb 6, 2024
1 check passed
@Arthie Arthie deleted the patch-1 branch February 6, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants