How to use the runtypes.Record function in runtypes

To help you get started, we’ve selected a few runtypes 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 pelotom / runtypes / examples / src / space-game.ts View on Github external
const CrewMember = Record({
  name: String,
  age: NonNegative,
  rank: Rank,
  home: Planet,
});
type CrewMember = Static<
  typeof CrewMember
>; /* = {
  name: string;
  age: NonNegative;
  rank: Rank;
  home: Planet;
}*/

const Ship = Record({
  type: Literal('ship'),
  location: Vector,
  mass: NonNegative,
  name: String,
  crew: Array(CrewMember),
});
type Ship = Static<
  typeof Ship
>; /* = {
  type: 'ship';
  location: Vector;
  mass: NonNegative;
  name: string;
  crew: CrewMember[];
}*/
github jschr / vscodethemes / types / runtime.ts View on Github external
trendingDaily: Number,
  trendingWeekly: Number,
  trendingMonthly: Number,
}).And(
  // Optional properties.
  Partial({
    displayName: String.Or(Null),
    shortDescription: String.Or(Null),
    repositoryUrl: String.Or(Null),
  }),
)

export const PackageJSONRuntime = Record({
  contributes: Record({
    themes: Array(
      Record({
        path: String,
      }).And(
        Partial({
          label: String,
          uiTheme: String,
        }),
      ),
    ),
  }),
})

export const ThemeTypeRuntime = Union(
  Literal('light'),
  Literal('dark'),
  Literal('hc'),
)
github hmil / rest.ts / test / fixtures / DTOs.ts View on Github external
export const TodoItemType = rt.Union(
    rt.Literal('housekeeping'),
    rt.Literal('work'),
    rt.Literal('shopping')
);

export const TodoItem = rt.Record({
    title: rt.String,
    done: rt.Boolean,
    type: TodoItemType
});


export const SavedTodoItem = rt.Intersect(
    TodoItem,
    rt.Record({
        id: rt.String
    })
);

export const SimpleMessage = rt.Record({
    message: rt.String
});

export const PathData = rt.Record({
    path: rt.String,
    kind: rt.String,
    id: rt.String
});

export class ClassBasedRequest {
    constructor(
github hmil / rest.ts / test / fixtures / DTOs.ts View on Github external
export const TodoItem = rt.Record({
    title: rt.String,
    done: rt.Boolean,
    type: TodoItemType
});


export const SavedTodoItem = rt.Intersect(
    TodoItem,
    rt.Record({
        id: rt.String
    })
);

export const SimpleMessage = rt.Record({
    message: rt.String
});

export const PathData = rt.Record({
    path: rt.String,
    kind: rt.String,
    id: rt.String
});

export class ClassBasedRequest {
    constructor(
            public message: string,
            public kind: 'person' | 'cat') {
    }   
}
github klemola / foobar2000-web-ui / server / Models.ts View on Github external
genre: String,
    trackNumber: String,
    track: String,
    trackLength: Number,
    state: PlaybackState
})

export type TrackInfo = Static

export const Muted = Record({
    type: Literal('muted')
})

export type Muted = Static

export const Audible = Record({
    type: Literal('audible'),
    volume: Number
})

export type Audible = Static

export const Volume = Union(Muted, Audible)

export type Volume = Static

export const InfoMessage = Record({
    type: Literal('info'),
    data: String
})

export type InfoMessage = Static
github klemola / foobar2000-web-ui / server / Models.ts View on Github external
export const InfoMessage = Record({
    type: Literal('info'),
    data: String
})

export type InfoMessage = Static

export const PlaybackMessage = Record({
    type: Literal('playback'),
    data: TrackInfo
})

export type PlaybackMessage = Static

export const VolumeMessage = Record({
    type: Literal('volume'),
    data: Volume
})

export type VolumeMessage = Static

export const Message = Union(InfoMessage, PlaybackMessage, VolumeMessage)

export type Message = Static
github jschr / vscodethemes / types / runtime.ts View on Github external
fontWeight: String,
    fontStyle: String,
    textDecoration: String,
  }),
})

export const LineTokensRuntime = Array(LineTokenRuntime)

export const LanguageTokensRuntime = Record({
  javascript: Array(LineTokensRuntime),
  html: Array(LineTokensRuntime),
  css: Array(LineTokensRuntime),
})

export const SaveThemePayloadRuntime = ExtractThemesPayloadRuntime.And(
  Record({
    themeId: String,
    themeName: String,
    themeType: ThemeTypeRuntime,
    colors: ColorsRuntime,
    languageTokens: LanguageTokensRuntime,
  }),
)