當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript spec.assert方法代碼示例

本文整理匯總了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);
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:29,代碼來源:js.spec-tests.ts

示例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 } });
開發者ID:DenisCarriere,項目名稱:DefinitelyTyped,代碼行數:29,代碼來源:js.spec-tests.ts


注:本文中的js.spec.assert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。