How to use the io-ts.interface function in io-ts

To help you get started, we’ve selected a few io-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / beats_management / common / domain_types.ts View on Github external
color: t.string,
    hasConfigurationBlocksTypes: t.array(t.string),
  },
  'CMBeat'
);
export interface BeatTag
  extends Pick<
    t.TypeOf,
    Exclude, 'id'>
  > {
  id: string;
  // Used by the UI and api when a tag exists but is an invalid option
  disabled?: boolean;
}

export const RuntimeBeatEvent = t.interface(
  {
    type: t.union([t.literal('STATE'), t.literal('ERROR')]),
    beat: t.union([t.undefined, t.string]),
    timestamp: DateFromString,
    event: t.type({
      type: t.union([
        t.literal('RUNNING'),
        t.literal('STARTING'),
        t.literal('IN_PROGRESS'),
        t.literal('CONFIG'),
        t.literal('FAILED'),
        t.literal('STOPPED'),
      ]),
      message: t.string,
      uuid: t.union([t.undefined, t.string]),
    }),
github teamdigitale / io-functions / lib / api / definitions / NewMessageDefaultAddresses.ts View on Github external
// tslint:disable:jsdoc-format
// tslint:disable:interface-name
// tslint:disable:no-any
// tslint:disable:object-literal-sort-keys

import { EmailAddress } from "./EmailAddress";

/**
 * Default addresses for notifying the recipient of the message in case no address for the related channel is set in his profile.
 */

import * as t from "io-ts";
import { strictInterfaceWithOptionals } from "../../utils/types";

// required attributes
const NewMessageDefaultAddressesR = t.interface({});

// optional attributes
const NewMessageDefaultAddressesO = t.partial({
  email: EmailAddress
});

export const NewMessageDefaultAddresses = strictInterfaceWithOptionals(
  NewMessageDefaultAddressesR.props,
  NewMessageDefaultAddressesO.props,
  "NewMessageDefaultAddresses"
);

export type NewMessageDefaultAddresses = t.TypeOf<
  typeof NewMessageDefaultAddresses
>;
github gcanti / prop-types-ts / test / index.tsx View on Github external
it('should check excess props', () => {
    const T = t.interface({ name: t.string })
    assertError(T, { name: 'name', a: 1 }, '\nInvalid additional prop(s): ["a"]')
  })
github DenisFrezzato / hyper-ts-fastify / test / index.ts View on Github external
it('should validate all params (success case)', () => {
        const m = H.decodeParams(t.interface({ foo: t.number }).decode)
        const c = new MockConnection(new MockRequest({ foo: 1 }))
        return assertSuccess(m, c, { foo: 1 }, [])
      })
github C5T / Current / typesystem / schema / golden / smoke_test_struct.ts View on Github external
a: C5TCurrent.Int32_IO,
}, 'A');
export type A = iots.TypeOf;

export const B_IO = iots.intersection([ A_IO, iots.interface({
  b: C5TCurrent.Int32_IO,
}) ], 'B');
export type B = iots.TypeOf;

export const B2_IO = iots.intersection([ A_IO ], 'B2');
export type B2 = iots.TypeOf;

export const Empty_IO = iots.interface({}, 'Empty');
export type Empty = iots.TypeOf;

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

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

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

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;

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") ]), });
github C5T / Current / typesystem / schema / golden / smoke_test_struct.ts View on Github external
export const C5TCurrentVariant_T9227782347108675041_IO = iots.union([
  C5TCurrentVariant_T9227782347108675041_VariantCase_A_IO,
  C5TCurrentVariant_T9227782347108675041_VariantCase_X_IO,
  C5TCurrentVariant_T9227782347108675041_VariantCase_Y_IO,
  iots.null,
], 'C5TCurrentVariant_T9227782347108675041');
export type C5TCurrentVariant_T9227782347108675041 = iots.TypeOf;

export const C_IO = iots.interface({
  e: Empty_IO,
  c: MyFreakingVariant_IO,
  d: C5TCurrentVariant_T9227782347108675041_IO,
}, 'C');
export type C = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_VariantCase_A_IO = iots.interface({ "A": A_IO, "": iots.union([ iots.undefined, iots.literal("T9206911749438269255") ]), "$": iots.union([ iots.undefined, iots.literal("T9206911749438269255") ]), });
export type C5TCurrentVariant_T9228482442669086788_VariantCase_A = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_VariantCase_B_IO = iots.interface({ "B": B_IO, "": iots.union([ iots.undefined, iots.literal("T9200817599233955266") ]), "$": iots.union([ iots.undefined, iots.literal("T9200817599233955266") ]), });
export type C5TCurrentVariant_T9228482442669086788_VariantCase_B = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_VariantCase_B2_IO = iots.interface({ "B2": B2_IO, "": iots.union([ iots.undefined, iots.literal("T9209827283478105543") ]), "$": iots.union([ iots.undefined, iots.literal("T9209827283478105543") ]), });
export type C5TCurrentVariant_T9228482442669086788_VariantCase_B2 = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_VariantCase_C_IO = iots.interface({ "C": C_IO, "": iots.union([ iots.undefined, iots.literal("T9202971611369570493") ]), "$": iots.union([ iots.undefined, iots.literal("T9202971611369570493") ]), });
export type C5TCurrentVariant_T9228482442669086788_VariantCase_C = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_VariantCase_Empty_IO = iots.interface({ "Empty": Empty_IO, "": iots.union([ iots.undefined, iots.literal("T9200000002835747520") ]), "$": iots.union([ iots.undefined, iots.literal("T9200000002835747520") ]), });
export type C5TCurrentVariant_T9228482442669086788_VariantCase_Empty = iots.TypeOf;

export const C5TCurrentVariant_T9228482442669086788_IO = iots.union([
  C5TCurrentVariant_T9228482442669086788_VariantCase_A_IO,
github gcanti / io-ts-codegen / test / fixtures / expected.ts View on Github external
import * as t from 'io-ts'

export type Health = {
  /** Name of the service. */
  id: string,
  /** Version of the service. */
  version: string,
  /** Current UTC date and time of the request, in ISO 8601 format. */
  currentAsOfUtc: string
}

export const Health = t.interface({
  /** Name of the service. */
  id: t.string,
  /** Version of the service. */
  version: t.string,
  /** Current UTC date and time of the request, in ISO 8601 format. */
  currentAsOfUtc: t.string
})

export type ICQAlertCategory =
  | 'Critical'
  | 'Alert'
  | 'Notification'

export const ICQAlertCategory = t.keyof({
  Critical: true,
  Alert: true,
github elastic / kibana / x-pack / legacy / plugins / beats_management / public / lib / adapters / framework / adapter_types.ts View on Github external
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 {}
github elastic / kibana / x-pack / legacy / plugins / ingest / server / libs / adapters / configurations / adapter_types.ts View on Github external
export const NewRuntimeConfigurationFile = t.interface(
  {
    name: t.string,
    description: t.string,
    output: t.string,
    monitoring_enabled: t.boolean,
    shared_id: t.string,
    version: t.number,
    agent_version: t.string,
    data_sources: t.array(DataSource),
  },
  'ConfigurationFile'
);

export const NewRuntimeBackupConfigurationFile = t.interface(
  {
    name: t.string,
    description: t.string,
    output: t.string,
    monitoring_enabled: t.boolean,
    agent_version: t.string,
    flat_data_sources: t.string,
  },
  'BackupConfigurationFile'
);

const ExistingDocument = t.interface({
  id: t.string,
  shared_id: t.string,
  version: t.number,
  status: t.union([t.literal('active'), t.literal('locked'), t.literal('inactive')]),
github yahiaetman / Go-Server / src / types / game-configuration.codec.ts View on Github external
winner: Color,
    reason: io.union([io.literal('resign'), io.literal('pass'), io.literal('timeout')]),
    scores: io.record(io.string, io.number) 
}, 'EndGameInfo');

export const LogEntry = io.intersection([
    io.type({
        deltaTime: ioe.withDefault(Time, 0)
    }),
    io.partial({
        move: Move,
        end: EndGameInfo
    })
]);

export const GameConfiguration = io.interface({
    initialState: GameState,
    moveLog: ioe.withDefault(io.array(LogEntry), []),
    idleDeltaTime: ioe.withDefault(Time, 0),
    komi: ioe.withDefault(io.number, 6.5),
    ko: ioe.withDefault(io.boolean, true),
    scoringMethod: ioe.withDefault(io.union([io.literal('area'), io.literal('territory')]), 'area'),
    prisonerScore: ioe.withDefault(io.number, 1)
}, 'GameConfiguration');