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


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

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


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

export const createConfigurationBlockInterface = (
  configType: t.LiteralType<string> | t.UnionType<Array<t.LiteralType<string>>> = t.union(
    configBlockSchemas.map(s => t.literal(s.id))
  ),
  beatConfigInterface: t.Mixed = t.Dictionary
) =>
  t.interface(
    {
      id: t.union([t.undefined, t.string]),
      type: configType,
      description: t.union([t.undefined, t.string]),
      tag: t.string,
      config: beatConfigInterface,
      last_updated: t.union([t.undefined, t.number]),
    },
    'ConfigBlock'
  );
开发者ID:elastic,项目名称:kibana,代码行数:17,代码来源:domain_types.ts

示例3:

  route: (routeConfig: any) => void;
  log: (message: string) => void;
}

export const RuntimeFrameworkInfo = t.interface(
  {
    kibana: t.type({
      version: t.string,
    }),
    license: t.type({
      type: t.union(
        ['oss', 'trial', 'standard', 'basic', 'gold', 'platinum'].map(s => t.literal(s))
      ),
      expired: t.boolean,
      expiry_date_in_millis: t.number,
    }),
    security: t.type({
      enabled: t.boolean,
      available: t.boolean,
    }),
    watcher: t.type({
      enabled: t.boolean,
      available: t.boolean,
    }),
  },
  'FrameworkInfo'
);
export interface FrameworkInfo extends t.TypeOf<typeof RuntimeFrameworkInfo> {}

export const RuntimeKibanaServerRequest = t.interface(
  {
开发者ID:njd5475,项目名称:kibana,代码行数:31,代码来源:adapter_types.ts

示例4:

);

// ----------------------------------------------------------------------------
// Module: Either `source` or `modules` types.
// ----------------------------------------------------------------------------
const RWebpackStatsModule = t.union([
  RWebpackStatsModuleSource,
  RWebpackStatsModuleSynthetic,
  RWebpackStatsModuleModules,
]);

export type IWebpackStatsModule = t.TypeOf<typeof RWebpackStatsModule>;

// ----------------------------------------------------------------------------
// Array of modules.
// ----------------------------------------------------------------------------
const RWebpackStatsModules = t.array(RWebpackStatsModule);

export type IWebpackStatsModules = t.TypeOf<typeof RWebpackStatsModules>;

// ----------------------------------------------------------------------------
// The full webpack stats object.
// ----------------------------------------------------------------------------
// tslint:disable-next-line variable-name
export const RWebpackStats = t.interface({
  assets: RWebpackStatsAssets,
  modules: RWebpackStatsModules,
});

export type IWebpackStats = t.TypeOf<typeof RWebpackStats>;
开发者ID:FormidableLabs,项目名称:inspectpack,代码行数:30,代码来源:webpack-stats.ts

示例5:

import * as iots from 'io-ts';
import * as C5TCurrent from 'c5t-current-schema-ts';


export const Primitives_IO = iots.interface({
  // It's the "order" of fields that matters.
  a: C5TCurrent.UInt8_IO,

  // Field descriptions can be set in any order.
  b: C5TCurrent.UInt16_IO,
  c: C5TCurrent.UInt32_IO,
  d: C5TCurrent.UInt64_IO,
  e: C5TCurrent.Int8_IO,
  f: C5TCurrent.Int16_IO,
  g: C5TCurrent.Int32_IO,
  h: C5TCurrent.Int64_IO,
  i: C5TCurrent.Char_IO,
  j: C5TCurrent.String_IO,
  k: C5TCurrent.Float_IO,
  l: C5TCurrent.Double_IO,

  // Multiline
  // descriptions
  // can be used.
  m: C5TCurrent.Bool_IO,
  n: C5TCurrent.Microseconds_IO,
  o: C5TCurrent.Milliseconds_IO,
}, 'Primitives');
export type Primitives = iots.TypeOf<typeof Primitives_IO>;

export const C5TCurrentVector_C5TCurrentString_IO = C5TCurrent.Vector_IO(C5TCurrent.String_IO);
export type C5TCurrentVector_C5TCurrentString = iots.TypeOf<typeof C5TCurrentVector_C5TCurrentString_IO>;
开发者ID:grixa,项目名称:Current,代码行数:32,代码来源:smoke_test_struct.ts

示例6: register

export interface FrameworkInfo extends t.TypeOf<typeof RuntimeFrameworkInfo> {}

interface ManagementSection {
  register(
    sectionId: string,
    options: {
      visible: boolean;
      display: string;
      order: number;
      url: string;
    }
  ): void;
}
export interface ManagementAPI {
  getSection(sectionId: string): ManagementSection;
  hasItem(sectionId: string): boolean;
  register(sectionId: string, options: { display: string; icon: string; order: number }): void;
}

export const RuntimeFrameworkUser = t.interface(
  {
    username: t.string,
    roles: t.array(t.string),
    full_name: t.union([t.null, t.string]),
    email: t.union([t.null, t.string]),
    enabled: t.boolean,
  },
  'FrameworkUser'
);
export interface FrameworkUser extends t.TypeOf<typeof RuntimeFrameworkUser> {}
开发者ID:lucabelluccini,项目名称:kibana,代码行数:30,代码来源:adapter_types.ts


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