當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。