Skip to content

Commit

Permalink
Reorder overloaded type signatures and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed Dec 2, 2024
1 parent 3acedf5 commit 650001b
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,6 @@ abstract class AbstractType<Output = unknown> {
return value;
}

/**
* Return new optional type that can not be used as a standalone
* validator. Rather, it's meant to be used as a with object validators,
* to mark one of the object's properties as _optional_. Optional property
* types accept both the original type, `undefined` and missing properties.
*
* The optional `defaultFn` function, if provided, will be called each
* time a value that is missing or `undefined` is parsed.
*
* @param [defaultFn] - An optional function returning the default value.
*/
// Use `<X extends T>() => X` instead of `() => T` to make literal
// inference work when an optionals with defaultFn is used as a
// ObjectType property.
Expand All @@ -555,6 +544,17 @@ abstract class AbstractType<Output = unknown> {
): Type<Exclude<Output, undefined>>;
optional<T>(defaultFn: () => T): Type<Exclude<Output, undefined> | T>;
optional(): Optional<Output>;
/**
* Return new optional type that can not be used as a standalone
* validator. Rather, it's meant to be used as a with object validators,
* to mark one of the object's properties as _optional_. Optional property
* types accept both the original type, `undefined` and missing properties.
*
* The optional `defaultFn` function, if provided, will be called each
* time a value that is missing or `undefined` is parsed.
*
* @param [defaultFn] - An optional function returning the default value.
*/
optional<T>(
defaultFn?: () => T,
): Type<Exclude<Output, undefined> | T> | Optional<Output> {
Expand Down Expand Up @@ -641,6 +641,10 @@ abstract class AbstractType<Output = unknown> {
);
}

map<T extends Literal>(
func: (v: Output, options: ParseOptions) => T,
): Type<T>;
map<T>(func: (v: Output, options: ParseOptions) => T): Type<T>;
/**
* Derive a new validator that uses the provided mapping function to
* perform custom mapping for the source validator's output values.
Expand All @@ -660,17 +664,19 @@ abstract class AbstractType<Output = unknown> {
*
* @param func - The mapping function.
*/
map<T extends Literal>(
func: (v: Output, options: ParseOptions) => T,
): Type<T>;
map<T>(func: (v: Output, options: ParseOptions) => T): Type<T>;
map<T>(func: (v: Output, options: ParseOptions) => T): Type<T> {
return new TransformType(this, (v, options) => ({
ok: true,
value: func(v as Output, options),
}));
}

chain<T extends Literal>(
func: (v: Output, options: ParseOptions) => ValitaResult<T>,
): Type<T>;
chain<T>(
func: (v: Output, options: ParseOptions) => ValitaResult<T>,
): Type<T>;
/**
* Derive a new validator that uses the provided mapping function to
* perform custom parsing for the source validator's output values.
Expand Down Expand Up @@ -698,12 +704,6 @@ abstract class AbstractType<Output = unknown> {
*
* @param func - The parsing function.
*/
chain<T extends Literal>(
func: (v: Output, options: ParseOptions) => ValitaResult<T>,
): Type<T>;
chain<T>(
func: (v: Output, options: ParseOptions) => ValitaResult<T>,
): Type<T>;
chain<T>(
func: (v: Output, options: ParseOptions) => ValitaResult<T>,
): Type<T> {
Expand Down

0 comments on commit 650001b

Please sign in to comment.