Skip to content

TypeScript declaration errors: Public API references inaccessible types like _CreateBaseQueryOptions and unique symbolΒ #216

@ghry5

Description

@ghry5

Which @ngneat/query-* package(s) are the source of the bug?

query

Is this a regression?

No

Description

Description

When using @ngneat/query in a library with compilerOptions.declaration: true in the tsconfig, TypeScript fails to generate declaration files if a public method or property uses types inferred from queryOptions or similar helpers. The error is:

The inferred type of 'getUserOptions' references an inaccessible 'unique symbol' type. A type annotation is necessary.ts(2527)
Public property 'getUser' of exported class has or is using name '_CreateBaseQueryOptions' from external module ".../node_modules/@ngneat/query/index" but cannot be named.ts(4029)

Example

import { Injectable, inject } from '@angular/core';
import { injectQuery } from '@ngneat/query';

@Injectable({ providedIn: 'root' })
export class UsersService {
  #query = injectQuery();

  // This causes the error when generating .d.ts files
  getUser(userId: number) {
    return this.#query({
      queryKey: ['users', userId] as const,
      queryFn: () => fetchUser(userId),
    });
  }
}

To Reproduce:

  • Use @ngneat/query in a library project.
  • Set compilerOptions.declaration: true in tsconfig.
  • Add a public property or method that uses queryOptions or similar helpers without an explicit type annotation.

Expected behavior
TypeScript should be able to generate declaration files without errors, or the library should provide exported types for use in public APIs.

Workaround
Explicitly annotate the type using Exported types. This sadly requires defining a custom Result Type as it is not exported publicly by ngneat:

export interface QueryResult<TData, TError> {
  result: Signal<QueryObserverResult<TData, TError>>;
  result$: Observable<QueryObserverResult<TData, TError>>;
}

getUser(userId: number): QueryResult<User, unknown>{
...

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in


Anything else?

No response

Do you want to create a pull request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions