Skip to content

Commit

Permalink
Simplify type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Oct 15, 2023
1 parent 527745d commit 3edabaf
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export function string(value: unknown): string {
return value;
}

export function stringUnion<T extends [string, ...Array<string>]>(
variants: readonly [...T],
): Decoder<T[number]> {
export function stringUnion<
const T extends readonly [string, ...Array<string>],
>(variants: T): Decoder<T[number]> {
return function stringUnionDecoder(value: unknown): T[number] {
const str = string(value);
if (!variants.includes(str)) {
Expand Down Expand Up @@ -312,9 +312,9 @@ export function fieldsUnion<T extends Record<string, Decoder<unknown>>>(
}

export function tuple<T extends Array<unknown>>(
mapping: readonly [...{ [P in keyof T]: Decoder<T[P]> }],
): Decoder<[...T]> {
return function tupleDecoder(value: unknown): [...T] {
mapping: [...{ [P in keyof T]: Decoder<T[P]> }],
): Decoder<T> {
return function tupleDecoder(value: unknown): T {
const arr = unknownArray(value);
if (arr.length !== mapping.length) {
throw new DecoderError({
Expand All @@ -332,7 +332,7 @@ export function tuple<T extends Array<unknown>>(
throw DecoderError.at(error, index);
}
}
return result as [...T];
return result as T;
};
}

Expand Down Expand Up @@ -363,9 +363,9 @@ type MultiTypeName =
| "string"
| "undefined";

export function multi<Types extends [MultiTypeName, ...Array<MultiTypeName>]>(
types: readonly [...Types],
): Decoder<Multi<Types[number]>> {
export function multi<
Types extends readonly [MultiTypeName, ...Array<MultiTypeName>],
>(types: Types): Decoder<Multi<Types[number]>> {
return function multiDecoder(value): Multi<Types[number]> {
if (value === undefined) {
if (types.includes("undefined")) {
Expand Down

0 comments on commit 3edabaf

Please sign in to comment.