• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript io-ts.literal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中io-ts.literal函数的典型用法代码示例。如果您正苦于以下问题:TypeScript literal函数的具体用法?TypeScript literal怎么用?TypeScript literal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Error

export const validateConfigurationBlocks = (configurationBlocks: ConfigurationBlock[]) => {
  const validationMap = {
    isHosts: t.array(t.string),
    isString: t.string,
    isPeriod: t.string,
    isPath: t.string,
    isPaths: t.array(t.string),
    isYaml: t.string,
  };

  for (const [index, block] of configurationBlocks.entries()) {
    const blockSchema = configBlockSchemas.find(s => s.id === block.type);
    if (!blockSchema) {
      throw new Error(
        `Invalid config type of ${block.type} used in 'configuration_blocks' at index ${index}`
      );
    }

    const interfaceConfig = blockSchema.configs.reduce(
      (props, config) => {
        if (config.options) {
          props[config.id] = t.union(config.options.map(opt => t.literal(opt.value)));
        } else if (config.validation) {
          props[config.id] = validationMap[config.validation];
        }

        return props;
      },
      {} as t.Props
    );

    const runtimeInterface = createConfigurationBlockInterface(
      t.literal(blockSchema.id),
      t.interface(interfaceConfig)
    );

    const validationResults = runtimeInterface.decode(block);

    if (validationResults.isLeft()) {
      throw new Error(
        `configuration_blocks validation error, configuration_blocks at index ${index} is invalid. ${
          PathReporter.report(validationResults)[0]
        }`
      );
    }
  }
};
开发者ID:elastic,项目名称:kibana,代码行数:47,代码来源:config_block_validation.ts


示例2:

 props[config.id] = t.union(config.options.map(opt => t.literal(opt.value)));
开发者ID:elastic,项目名称:kibana,代码行数:1,代码来源:config_block_validation.ts


示例3:

 ['oss', 'trial', 'standard', 'basic', 'gold', 'platinum'].map(s => t.literal(s))
开发者ID:njd5475,项目名称:kibana,代码行数:1,代码来源:adapter_types.ts


示例4:

 configBlockSchemas.map(s => t.literal(s.id))
开发者ID:elastic,项目名称:kibana,代码行数:1,代码来源:domain_types.ts


示例5:

export type Empty = iots.TypeOf<typeof Empty_IO>;

export const X_IO = iots.interface({
  x: C5TCurrent.Int32_IO,
}, 'X');
export type X = iots.TypeOf<typeof X_IO>;

export const E_IO = C5TCurrent.Enum_IO('E');
export type E = iots.TypeOf<typeof E_IO>;

export const Y_IO = iots.interface({
  e: E_IO,
}, 'Y');
export type Y = iots.TypeOf<typeof Y_IO>;

export const MyFreakingVariant_VariantCase_A_IO = iots.interface({ "A": A_IO, "": iots.union([ iots.undefined, iots.literal("T9206911749438269255") ]), "$": iots.union([ iots.undefined, iots.literal("T9206911749438269255") ]), });
export type MyFreakingVariant_VariantCase_A = iots.TypeOf<typeof MyFreakingVariant_VariantCase_A_IO>;

export const MyFreakingVariant_VariantCase_X_IO = iots.interface({ "X": X_IO, "": iots.union([ iots.undefined, iots.literal("T9209980946934124423") ]), "$": iots.union([ iots.undefined, iots.literal("T9209980946934124423") ]), });
export type MyFreakingVariant_VariantCase_X = iots.TypeOf<typeof MyFreakingVariant_VariantCase_X_IO>;

export const MyFreakingVariant_VariantCase_Y_IO = iots.interface({ "Y": Y_IO, "": iots.union([ iots.undefined, iots.literal("T9208828720332602574") ]), "$": iots.union([ iots.undefined, iots.literal("T9208828720332602574") ]), });
export type MyFreakingVariant_VariantCase_Y = iots.TypeOf<typeof MyFreakingVariant_VariantCase_Y_IO>;

export const MyFreakingVariant_IO = iots.union([
  MyFreakingVariant_VariantCase_A_IO,
  MyFreakingVariant_VariantCase_X_IO,
  MyFreakingVariant_VariantCase_Y_IO,
  iots.null,
], 'MyFreakingVariant');
export type MyFreakingVariant = iots.TypeOf<typeof MyFreakingVariant_IO>;
开发者ID:grixa,项目名称:Current,代码行数:31,代码来源:smoke_test_struct.ts


示例6:

type: t.union(LICENSES.map(s => t.literal(s))),
开发者ID:lucabelluccini,项目名称:kibana,代码行数:1,代码来源:adapter_types.ts


示例7: useAppContext

import { useMemo } from 'react';
import * as t from 'io-ts';
import { useAppContext } from './useAppContext';

// Typed app routing via brilliant gcanti/io-ts.
// Soon in Next.js: https://twitter.com/timneutkens/status/1109092151907045376

const AppHrefIO = t.union([
  t.type({ pathname: t.literal('/') }),
  t.type({ pathname: t.literal('/me') }),
  t.type({ pathname: t.literal('https://twitter.com/steida') }),
  t.type({
    pathname: t.literal('/web'),
    query: t.type({ id: t.string }),
  }),
  // https://github.com/gcanti/io-ts#mixing-required-and-optional-props
  t.intersection([
    t.type({ pathname: t.literal('/signin') }),
    t.partial({ query: t.type({ redirectUrl: t.string }) }),
  ]),
]);

export type AppHref = t.TypeOf<typeof AppHrefIO>;

export const useAppHref = () => {
  const { router } = useAppContext();

  // This should be memoized globally. In serverless, it means per request :-)
  const current = useMemo<AppHref | undefined>(() => {
    let maybeAppHref: AppHref | undefined;
    const routerAppHref = { pathname: router.pathname, query: router.query };
开发者ID:este,项目名称:este,代码行数:31,代码来源:useAppHref.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript io-ts.partial函数代码示例发布时间:2022-05-25
下一篇:
TypeScript io-ts.intersection函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap