当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript spec.spec.predicate方法代码示例

本文整理汇总了TypeScript中js.spec.spec.predicate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript spec.spec.predicate方法的具体用法?TypeScript spec.spec.predicate怎么用?TypeScript spec.spec.predicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在js.spec.spec的用法示例。


在下文中一共展示了spec.spec.predicate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

const orSpec: S.Spec = S.spec.or("or test", { ball: (value: any) => value === "whale", fish: S.spec.number });

const nilableSpec: S.Spec = S.spec.nilable("nilable test", (value: any) => false);

const collectionSpec: S.Spec = S.spec.collection("collection test", S.spec.positive);

const collection2Spec: S.Spec = S.spec.collection("collection test", S.spec.string, {[S.symbol.count]: 3});

const tupleSpec: S.Spec = S.spec.tuple("tuple test", S.spec.bool, S.spec.date, S.spec.array);

const mapSpec: S.Spec = S.spec.map("map test", { email: S.spec.string, [S.symbol.optional]: { name: S.spec.string } });

const oneOfSpec: S.Spec = S.spec.oneOf("oneOf test", "a", "b", "c");

const predicateSpec: S.Spec = S.spec.predicate("predicate test", (value) => true);

// Predicates

const intPred: S.Predicate = S.spec.int;

const integerPred: S.Predicate = S.spec.integer;

const finitePred: S.Predicate = S.spec.finite;

const numberPred: S.Predicate = S.spec.number;

const oddPred: S.Predicate = S.spec.odd;

const evenPred: S.Predicate = S.spec.even;
开发者ID:Batbold-Gansukh,项目名称:DefinitelyTyped,代码行数:29,代码来源:js.spec-tests.ts

示例2:

import * as S from "js.spec";

const spec: S.Spec = S.spec.predicate("test spec", S.spec.bool);
const c: symbol = spec.conform("water");
const waterProblems: S.Problem[] = spec.explain(["data"], ["spec"], "water");
const toString: string = spec.toString();
const name: string = spec.name;
const options: object = spec.options;

const isValid: boolean = S.valid(S.spec.boolean, true);
S.valid((value) => true, "a value");

const result = S.conform(S.spec.map("dancing", {field: S.spec.string}), "not a map");
S.conform((value) => true, "a value");

const problems: S.Problem[] = S.explainData(S.spec.int, "not a number");
S.explainData((value) => true, "a value");

const {path, via, value, predicate}: {path: string[], via: string[], value: any, predicate: S.PredFn} = problems[0];

const problemStr: string = S.problemStr(problems[0]);

const explainStr: string = S.explainStr(S.spec.even, 3);
S.explainStr((value) => true, "a value");

// $ExpectType void
S.explain(S.spec.positive, true);
// $ExpectType void
S.explain((value) => true, "a value");

// $ExpectType void
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:31,代码来源:js.spec-tests.ts


注:本文中的js.spec.spec.predicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。