redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

FakeBaseQuery references an inaccessible 'unique symbol' type.

Open sebastienlabine opened this issue 3 years ago • 2 comments

Hi,

I am building a library that exports redux-toolkit generated hooks in order to reuse theses hooks in multiple applications.

I encountered a problem while using fakeBaseQuery as baseQuery making all my hooks unsuable with typescripts:

(!) Plugin typescript: @rollup/plugin-typescript TS2527: The inferred type of 'bankAccountsAPI' references an inaccessible 'unique symbol' type. A type annotation is necessary.
src/apis/smartbills-api/banks/BankAccountsAPI.tsx: (6:14)

6 export const bankAccountsAPI = smartbillsAPI
               ~~~~~~~~~~~~~~~

As we can see in the fakeBaseQuery type definition, we are using a pure Symbol for the never type.

const _NEVER = /* @__PURE__ */ Symbol()
export type NEVER = typeof _NEVER

is there a reason to do so? I bypassed the error by creating my "own" fakeBaseQuery using the never type.

import { BaseQueryFn } from "@reduxjs/toolkit/dist/query/react"

export function fakeBaseQuery<ErrorType>(): BaseQueryFn<
    void,
    never,
    ErrorType,
    {}
> {
    return function () {
        throw new Error(
            'When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.'
        )
    }
}

Thanks

sebastienlabine avatar May 10 '22 20:05 sebastienlabine

@sebastienlabine Hi, any solution about this error? I encountered the error too

ytftianwen avatar Sep 21 '22 09:09 ytftianwen

@ytftianwen yes, I actually just created my own fake base query and used it as my baseQuery

import { BaseQueryFn } from "@reduxjs/toolkit/dist/query/react"

export function fakeBaseQuery<ErrorType>(): BaseQueryFn<
    void,
    never,
    ErrorType,
    {}
> {
    return function () {
        throw new Error(
            'When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.'
        )
    }
}

sebastienlabine avatar Sep 21 '22 13:09 sebastienlabine

Not clear if this is still an issue, so closing.

markerikson avatar Dec 06 '23 13:12 markerikson