You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// private symbol to prevent narrowing on "default" error status
constnever: unique symbol=Symbol()
type_OpErrorType<T>={
[SinExclude<keyofT,200|201>]: {
status: Sextends'default' ? typeofnever : S
data: T[S]
}
}[Exclude<keyofT,200|201>]
If I modify that source code to export the type, the error I mentioned disappears with no further modifications needed in my own code:
// private symbol to prevent narrowing on "default" error status
-const never: unique symbol = Symbol()+export const never: unique symbol = Symbol()
type _OpErrorType<T> = {
[S in Exclude<keyof T, 200 | 201>]: {
status: S extends 'default' ? typeof never : S
data: T[S]
}
}[Exclude<keyof T, 200 | 201>]
Would it be feasible to add an export to this constant to resolve the "inaccessible unique symbol" error here?
Footnotes
makeHook is the name of the calling function in my code. ↩
The text was updated successfully, but these errors were encountered:
htunnicliff
changed the title
TypeScript error TS25when using FetchErrorType<F>
Inaccessible unique symbol error when using FetchErrorType
Jun 5, 2022
htunnicliff
changed the title
Inaccessible unique symbol error when using FetchErrorType
Inaccessible unique symbol error when using FetchErrorTypeJun 5, 2022
Here is an approximation of my calling code. The relevant part of the function is that it accepts an OpenAPI schema paths type in its generic, then lets the user enter one of the available path keys in order to generate a fetcher for the given path.
import{Fetcher}from"openapi-typescript-fetch";importtype{OpenapiPaths}from"openapi-typescript-fetch/dist/cjs/types";typeGettable={get: unknown;};typeOnlyGet<T>={[KinkeyofTasT[K]extendsGettable ? K : never]: T[K];};exportfunctionmakeHook<PathsextendsOpenapiPaths<Paths>,PathextendskeyofOnlyGet<Paths>>(path: Path){// Create fetcherconstfetcher=Fetcher.for<Paths>();fetcher.configure({});// Create requestconstrequest=fetcher.path(path).method("get").create();typeData=FetchReturnType<typeofrequest>;typeArgs=FetchArgType<typeofrequest>;typeFetchError=FetchErrorType<typeofrequest>;// <-- TS2527 error// ... do other stuff to create and return a hook }
When I attempt to use
FetchErrorType<F>
, TypeScript emits the following error:I investigated this and discovered that the following
const
declaration (on line 65) is the cause of the problem.openapi-typescript-fetch/src/types.ts
Lines 64 to 72 in 2e0d66e
If I modify that source code to export the type, the error I mentioned disappears with no further modifications needed in my own code:
Would it be feasible to add an
export
to this constant to resolve the "inaccessible unique symbol" error here?Footnotes
makeHook
is the name of the calling function in my code. ↩The text was updated successfully, but these errors were encountered: