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


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

本文整理汇总了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;未经允许,请勿转载。