Skip to content

Commit e46fff3

Browse files
committed
📝 Improve document and examples
1 parent 9c00592 commit e46fff3

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

is.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -754,20 +754,25 @@ type IsTupleOfMetadata = {
754754
/**
755755
* Return a type predicate function that returns `true` if the type of `x` is `ParametersOf<T>` or `ParametersOf<T, E>`.
756756
*
757-
* This is similar to `TupleOf<T>` or `TupleOf<T, E>`, except that the `OptionalOf<P>` at the end of the tuple becomes optional.
757+
* This is similar to `TupleOf<T>` or `TupleOf<T, E>`, but if `is.OptionalOf()` is specified at the trailing, the trailing elements becomes optional and makes variable-length tuple.
758758
*
759759
* To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
760760
*
761761
* ```ts
762762
* import { is } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts";
763763
*
764-
* const isMyType = is.ParametersOf(
765-
* [is.Number, is.String, is.OptionalOf(is.Boolean)] as const,
766-
* );
767-
* const a: unknown = [0, "a"];
764+
* const isMyType = is.ParametersOf([
765+
* is.Number,
766+
* is.OptionalOf(is.String),
767+
* is.Boolean,
768+
* is.OptionalOf(is.Number),
769+
* is.OptionalOf(is.String),
770+
* is.OptionalOf(is.Boolean),
771+
* ] as const);
772+
* const a: unknown = [0, undefined, "a"];
768773
* if (isMyType(a)) {
769-
* // a is narrowed to [number, string, boolean?]
770-
* const _: [number, string, boolean?] = a;
774+
* // a is narrowed to [number, string | undefined, boolean, number?, string?, boolean?]
775+
* const _: [number, string | undefined, boolean, number?, string?, boolean?] = a;
771776
* }
772777
* ```
773778
*
@@ -777,7 +782,11 @@ type IsTupleOfMetadata = {
777782
* import { is } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts";
778783
*
779784
* const isMyType = is.ParametersOf(
780-
* [is.Number, is.OptionalOf(is.String), is.OptionalOf(is.Boolean)] as const,
785+
* [
786+
* is.Number,
787+
* is.OptionalOf(is.String),
788+
* is.OptionalOf(is.Boolean),
789+
* ] as const,
781790
* is.ArrayOf(is.Number),
782791
* );
783792
* const a: unknown = [0, "a", true, 0, 1, 2];

0 commit comments

Comments
 (0)