UNPKG

@peppierre/typesafe-http-iots

Version:

Type-safe HTTP client for Angular using io-ts and fp-ts

55 lines (48 loc) 2.61 kB
import { HttpClient } from '@angular/common/http'; import * as iots from 'io-ts'; import { Observable } from 'rxjs'; import * as i0 from '@angular/core'; import { Provider } from '@angular/core'; type HttpClientOverloads<T> = T extends { (...args: infer A01): infer R01; (...args: infer A02): infer R02; (...args: infer A03): infer R03; (...args: infer A04): infer R04; (...args: infer A05): infer R05; (...args: infer A06): infer R06; (...args: infer A07): infer R07; (...args: infer A08): infer R08; (...args: infer A09): infer R09; (...args: infer A10): infer R10; (...args: infer A11): infer R11; (...args: infer A12): infer R12; (...args: infer A13): infer R13; (...args: infer A14): infer R14; (...args: infer A15): infer R15; } ? [A01, R01] | [A02, R02] | [A03, R03] | [A04, R04] | [A05, R05] | [A06, R06] | [A07, R07] | [A08, R08] | [A09, R09] | [A10, R10] | [A11, R11] | [A12, R12] | [A13, R13] | [A14, R14] | [A15, R15] : never; type WrapOverload<T extends unknown[], R> = <R>(// eslint-disable-line @typescript-eslint/no-unused-vars ...args: [runtimeType: iots.Type<R, unknown, unknown>, ...params: T]) => Observable<R>; type WrapOverloads<T> = HttpClientOverloads<T> extends infer O ? O extends [infer Args extends unknown[], infer R] ? WrapOverload<Args, R> : never : never; type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never; type WrappedGet = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.get>>; type WrappedPost = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.post>>; type WrappedPut = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.put>>; type WrappedPatch = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.patch>>; type WrappedDelete = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.delete>>; type WrappedHead = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.head>>; type WrappedOptions = UnionToIntersection<WrapOverloads<typeof HttpClient.prototype.options>>; declare class TypesafeHttpService { private http; constructor(http: HttpClient); get: WrappedGet; post: WrappedPost; put: WrappedPut; patch: WrappedPatch; delete: WrappedDelete; head: WrappedHead; options: WrappedOptions; static ɵfac: i0.ɵɵFactoryDeclaration<TypesafeHttpService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<TypesafeHttpService>; } declare function provideTypesafeHttp(): Provider; export { TypesafeHttpService, provideTypesafeHttp };