Commit 635a1aae by Vladislav Lagunov

Упрощение декодеров

parent 66f77534
...@@ -328,14 +328,9 @@ export { anyDecoder as any, stringDecoder as string, booleanDecoder as boolean, ...@@ -328,14 +328,9 @@ export { anyDecoder as any, stringDecoder as string, booleanDecoder as boolean,
* Сопоставление с несколькими декодерами до первого успешного * Сопоставление с несколькими декодерами до первого успешного
* сравнвния * сравнвния
*/ */
export function oneOf<A>(a: Decoder<A>): OneOf<A>; export function oneOf<XS extends Decoder<any>[]>(...array: XS): OneOf<XS[number]['_A']>;
export function oneOf<A,B>(a: Decoder<A>, b: Decoder<B>): OneOf<A|B>; export function oneOf<XS extends Decoder<any>[]>(array: XS): OneOf<XS[number]['_A']>;
export function oneOf<A,B,C>(a: Decoder<A>, b: Decoder<B>, c: Decoder<C>): OneOf<A|B|C>; export function oneOf(): OneOf<any> {
export function oneOf<A,B,C,D>(a: Decoder<A>, b: Decoder<B>, c: Decoder<C>, d: Decoder<D>): OneOf<A|B|C|D>;
export function oneOf<A,B,C,D,E>(a: Decoder<A>, b: Decoder<B>, c: Decoder<C>, d: Decoder<D>, e: Decoder<E>): OneOf<A|B|C|D|E>;
export function oneOf<A,B,C,D,E,F>(a: Decoder<A>, b: Decoder<B>, c: Decoder<C>, d: Decoder<D>, e: Decoder<E>, f: Decoder<F>): OneOf<A|B|C|D|E|F>;
export function oneOf<array extends Decoder<any>[]>(array: array): Decoder<array[number]['_A']>;
export function oneOf(): Decoder<any> {
const decoders = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.call(arguments); const decoders = Array.isArray(arguments[0]) ? arguments[0] : Array.prototype.slice.call(arguments);
return new OneOf(decoders); return new OneOf(decoders);
} }
...@@ -345,7 +340,7 @@ export function array<A>(decoder: Decoder<A>): Decoder<A[]> { ...@@ -345,7 +340,7 @@ export function array<A>(decoder: Decoder<A>): Decoder<A[]> {
return new ArrayDecoder(decoder); return new ArrayDecoder(decoder);
} }
export function record<fields extends { [k: string]: Decoder<any> }>(fields: fields): RecordDecoder<{[k in keyof fields]: fields[k]['_A'] }> { export function record<T>(fields: { [K in keyof T]: Decoder<T[K]> }): RecordDecoder<T> {
return new RecordDecoder(fields); return new RecordDecoder(fields);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment