本文整理汇总了TypeScript中boxed_value.box函数的典型用法代码示例。如果您正苦于以下问题:TypeScript box函数的具体用法?TypeScript box怎么用?TypeScript box使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了box函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: fetchStoredToken
export function fetchStoredToken(): AuthState | undefined {
try {
const v: AuthState = JSON.parse(localStorage.getItem(KEY) || "");
if (box(v).kind === "object") {
return v;
} else {
throw new Error("Expected object or undefined"); // unreachable?
}
} catch (error) {
return undefined;
}
}
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:12,代码来源:session.ts
示例2: get
export function get(): AuthState | undefined {
try {
let v: AuthState = JSON.parse(localStorage[KEY]);
if (box(v).kind === "object") {
return v;
} else {
throw new Error("Expected object or undefined");
}
} catch (error) {
return undefined;
}
}
开发者ID:MrChristofferson,项目名称:Farmbot-Web-API,代码行数:12,代码来源:session.ts
示例3: safeStringFetch
export function safeStringFetch(obj: {}, key: string): string {
const boxed = box((obj as Dictionary<{}>)[key]);
switch (boxed.kind) {
case "undefined":
case "null":
return "";
case "number":
case "string":
return boxed.value.toString();
case "boolean":
return (boxed.value) ? "true" : "false";
default:
const msg = t(`Numbers strings and null only (got ${boxed.kind}).`);
throw new Error(msg);
}
}
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:16,代码来源:util.ts
示例4: box
parse: (__, val) => {
try {
const b = box(JSON.parse(val));
switch (b.kind) {
case "number":
return b.value;
case "boolean":
case "string":
return getSpecialValue(val);
default:
throw new Error("BAD DATA TYPE");
}
} catch (error) {
throw new Error(`An input from FarmWare caused a crash.
This is the value we got: ${val}
This is the error: ${error}
`);
}
}
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:20,代码来源:constants.ts
示例5: isSafeError
export function isSafeError(x: SafeError | any): x is SafeError {
return !!(
(box(x).kind === "object") &&
(box(x.response).kind === "object") &&
(box(x.response.status).kind === "number"));
}
开发者ID:FarmBot,项目名称:Farmbot-Web-API,代码行数:6,代码来源:interceptor_support.ts
注:本文中的boxed_value.box函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论