How to use the runtypes.Array 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
});
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[];
}*/

const Fleet = Dictionary(Ship, 'number');
type Fleet = Static; // = { [_: number]: Ship }

const SpaceObject = Union(Asteroid, Planet, Ship);
type SpaceObject = Static; // = Asteroid | Planet | Ship
github jschr / vscodethemes / types / runtime.ts View on Github external
files: Array(FilesRuntime),
})

export const StatisticRuntime = Record({
  statisticName: String,
  value: Number,
})

export const ExtensionRuntime = Record({
  extensionId: String,
  extensionName: String,
  lastUpdated: String,
  publishedDate: String,
  releaseDate: String,
  publisher: PublisherRuntime,
  versions: Array(VersionRuntime),
  statistics: Array(StatisticRuntime),
}).And(
  // Optional properties.
  Partial({
    displayName: String,
    shortDescription: String,
  }),
)

export const ExtensionQueryResultsRuntime = Record({
  results: Tuple(Record({ extensions: Array(ExtensionRuntime) })),
})

export const ScrapeExtensionsPayloadRuntime = Record({
  page: Number,
})
github typeetfunc / runtypes-generate / src / custom.spec.ts View on Github external
type,
    members: ArrayWithContains(Array(Member), Spouse, countSpouse)
  })
  const FamilyWithSpouse = FamilyWithTypeAndMember(
    Literal('espoused'),
    1
  )
  const FamilyWithoutSpouse = FamilyWithTypeAndMember(
    Union(
      Literal('single'),
      Literal('common_law_marriage'),
      Void
    ),
    0
  )
  const membersWithSpouse = ArrayWithContains(Array(Member), Spouse, 1)
  const FamilyObject = Union(FamilyWithSpouse, FamilyWithoutSpouse)
  test('Fio', generateAndCheck(Fio))
  test('Member', generateAndCheck(Member))
  test('Member', generateAndCheck(Member))
  test('MemberWithSpouse', generateAndCheck(membersWithSpouse))
  test('FamilyWithSpouse', generateAndCheck(FamilyWithSpouse))
  test('FamilyWithoutSpouse', generateAndCheck(FamilyWithoutSpouse))
  test('FamilyObject', generateAndCheck(FamilyObject))
});
github typeetfunc / runtypes-generate / src / custom.spec.ts View on Github external
const FamilyWithTypeAndMember = (type, countSpouse) => Record({
    type,
    members: ArrayWithContains(Array(Member), Spouse, countSpouse)
  })
  const FamilyWithSpouse = FamilyWithTypeAndMember(
github jschr / vscodethemes / types / runtime.ts View on Github external
export const LineTokenRuntime = Record({
  token: String,
  style: Partial({
    color: String,
    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,
  }),
)