You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: is.ts
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -754,20 +754,25 @@ type IsTupleOfMetadata = {
754
754
/**
755
755
* Return a type predicate function that returns `true` if the type of `x` is `ParametersOf<T>` or `ParametersOf<T, E>`.
756
756
*
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.
758
758
*
759
759
* To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
760
760
*
761
761
* ```ts
762
762
* import { is } from "https://deno.land/x/unknownutil@$MODULE_VERSION/mod.ts";
763
763
*
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"];
768
773
* 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?]
0 commit comments