本文整理汇总了TypeScript中js.spec.assert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript spec.assert方法的具体用法?TypeScript spec.assert怎么用?TypeScript spec.assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js.spec
的用法示例。
在下文中一共展示了spec.assert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
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.Predicate} = problems[0];
const problemStr: 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
S.assert(S.spec.string, "things");
// $ExpectType void
S.assert((value) => true, "a value");
const symbols: symbol[] = [S.symbol.count, S.symbol.invalid, S.symbol.maxCount, S.symbol.minCount, S.symbol.optional];
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);
示例2:
const isValid: boolean = S.valid(S.spec.boolean, true);
const result = S.conform(S.spec.map("dancing", {field: S.spec.string}), "not a map");
const problems: S.Problem[] = S.explainData(S.spec.int, "not a number");
const {path, via, value, predicate}: {path: string[], via: string[], value: any, predicate: S.Predicate} = problems[0];
const problemStr: string = S.explainStr(S.spec.even, 3);
// $ExpectType void
S.explain(S.spec.positive, true);
// $ExpectType void
S.assert(S.spec.string, "things");
const symbols: symbol[] = [S.symbol.count, S.symbol.invalid, S.symbol.maxCount, S.symbol.minCount, S.symbol.optional];
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 } });