本文整理汇总了TypeScript中io-ts.type函数的典型用法代码示例。如果您正苦于以下问题:TypeScript type函数的具体用法?TypeScript type怎么用?TypeScript type使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了type函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getStaticDefaultSourceConfiguration
private async getStaticDefaultSourceConfiguration() {
const staticConfiguration = await this.libs.configuration.get();
const staticSourceConfiguration = runtimeTypes
.type({
sources: runtimeTypes.type({
default: PartialInfraSourceConfigurationRuntimeType,
}),
})
.decode(staticConfiguration)
.map(({ sources: { default: defaultConfiguration } }) => defaultConfiguration)
.getOrElse({});
return mergeSourceConfiguration(defaultSourceConfiguration, staticSourceConfiguration);
}
示例2:
(self) => t.intersection([
RWebpackStatsModuleBase,
t.type({
// More levels of modules.
// https://webpack.js.org/api/stats/#module-objects
modules: t.array(t.union([
RWebpackStatsModuleSource,
self,
])),
}),
]),
示例3: getAllOrders
import * as t from "io-ts";
import * as Knex from "knex";
import { AllOrdersRow } from "../../types";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
export const AllOrdersParams = t.type({
account: t.string,
});
export interface AllOrders {
[orderId: string]: AllOrdersRow<string>;
}
export async function getAllOrders(db: Knex, augur: {}, params: t.TypeOf<typeof AllOrdersParams>): Promise<AllOrders> {
const query = db.select(
[
"orderId",
"marketId",
"originalTokensEscrowed",
"originalSharesEscrowed",
"tokensEscrowed",
"sharesEscrowed",
]).from("orders")
.where("orderCreator", params.account)
.where("orderState", "OPEN");
const allOrders: Array<AllOrdersRow<BigNumber>> = await query;
return allOrders.reduce((acc: AllOrders, cur: AllOrdersRow<BigNumber>) => {
acc[cur.orderId] = formatBigNumberAsFixed<AllOrdersRow<BigNumber>, AllOrdersRow<string>>({
orderId: cur.orderId,
originalTokensEscrowed: cur.originalTokensEscrowed,
originalSharesEscrowed: cur.originalSharesEscrowed,
示例4: unionWithNullType
updated: unionWithNullType(runtimeTypes.number),
updatedBy: unionWithNullType(runtimeTypes.string),
});
export interface SavedTimeline extends runtimeTypes.TypeOf<typeof SavedTimelineRuntimeType> {}
export interface SavedTimelineNote extends runtimeTypes.TypeOf<typeof SavedTimelineRuntimeType> {}
/**
* Timeline Saved object type with metadata
*/
export const TimelineSavedObjectRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
id: runtimeTypes.string,
attributes: SavedTimelineRuntimeType,
version: runtimeTypes.string,
}),
runtimeTypes.partial({
savedObjectId: runtimeTypes.string,
}),
]);
export const TimelineSavedToReturnObjectRuntimeType = runtimeTypes.intersection([
SavedTimelineRuntimeType,
runtimeTypes.type({
savedObjectId: runtimeTypes.string,
version: runtimeTypes.string,
}),
runtimeTypes.partial({
eventIdToNoteIds: runtimeTypes.array(NoteSavedObjectToReturnRuntimeType),
示例5: getSyncData
import * as t from "io-ts";
import * as Knex from "knex";
import Augur from "augur.js";
import { isSyncFinished } from "../../blockchain/bulk-sync-augur-node-with-blockchain";
import { version } from "../../version";
export const NoParams = t.type({
});
export interface UISyncData {
version: string;
augurNodeVersion: string;
net_version: string;
netId: string;
isSyncFinished: boolean;
addresses: {};
highestBlock: {};
lastProcessedBlock: {};
}
export async function getSyncData(db: Knex, augur: Augur, params: t.TypeOf<typeof NoParams>): Promise<UISyncData> {
const currentBlock = augur.rpc.getCurrentBlock();
const highestBlock = {
number: parseInt(currentBlock.number, 16),
hash: currentBlock.hash,
timestamp: parseInt(currentBlock.timestamp, 16),
};
const lastProcessedBlock = await db("blocks").first(["blockNumber as number", "blockHash as hash", "timestamp"]).orderBy("blockNumber", "DESC");
return {
version: augur.version,
augurNodeVersion: version,
示例6: getForkMigrationTotals
import * as t from "io-ts";
import * as Knex from "knex";
import Augur from "augur.js";
import { BigNumber } from "bignumber.js";
import { ForkMigrationTotalsRow, UIForkMigrationTotals, UIForkMigrationTotalsRow } from "../../types";
import { formatBigNumberAsFixed } from "../../utils/format-big-number-as-fixed";
export const ForkMigrationTotalsParams = t.type({
parentUniverse: t.string,
});
export async function getForkMigrationTotals(db: Knex, augur: Augur, params: t.TypeOf<typeof ForkMigrationTotalsParams>) {
const query = db.select([
"universe",
"payouts.isInvalid",
"payouts.payout0",
"payouts.payout1",
"payouts.payout2",
"payouts.payout3",
"payouts.payout4",
"payouts.payout5",
"payouts.payout6",
"payouts.payout7",
"token_supply.supply AS repTotal"]).from("universes")
.join("token_supply", "universes.reputationToken", "token_supply.token")
.join("payouts", "payouts.marketId", "universes.universe")
.where("universes.parentUniverse", params.parentUniverse);
const forkMigrationTotals: Array<ForkMigrationTotalsRow<BigNumber>> = await query;
return forkMigrationTotals.reduce((acc: UIForkMigrationTotals<string>, cur) => {
const payout: Array<string> = [
示例7: moment
runtimeTypes.string.validate(input, context).chain(stringInput => {
const momentValue = moment(stringInput);
return momentValue.isValid()
? runtimeTypes.success(momentValue.valueOf())
: runtimeTypes.failure(stringInput, context);
}),
output => new Date(output).toISOString()
);
export const InfraSourceConfigurationRuntimeType = runtimeTypes.type({
name: runtimeTypes.string,
description: runtimeTypes.string,
metricAlias: runtimeTypes.string,
logAlias: runtimeTypes.string,
fields: runtimeTypes.type({
container: runtimeTypes.string,
host: runtimeTypes.string,
pod: runtimeTypes.string,
tiebreaker: runtimeTypes.string,
timestamp: runtimeTypes.string,
}),
});
export interface InfraSourceConfiguration
extends runtimeTypes.TypeOf<typeof InfraSourceConfigurationRuntimeType> {}
export const PartialInfraSourceConfigurationRuntimeType = runtimeTypes.partial({
...InfraSourceConfigurationRuntimeType.props,
fields: runtimeTypes.partial(InfraSourceConfigurationRuntimeType.props.fields.props),
});
示例8: getCategoriesRows
import * as t from "io-ts";
import * as Knex from "knex";
import * as _ from "lodash";
import Augur from "augur.js";
import BigNumber from "bignumber.js";
import { CategoriesRow, UICategory, TagAggregation, ReportingState } from "../../types";
export const CategoriesParams = t.type({
universe: t.string,
});
interface MarketsTagRow {
category: string;
openInterest: BigNumber;
reportingState: ReportingState;
tag1: string;
tag2: string;
}
export async function getCategoriesRows(db: Knex, universe: string): Promise<Array<CategoriesRow<BigNumber>>> {
return db.select(["category", "nonFinalizedOpenInterest", "openInterest", "universe"]).from("categories").where({ universe });
}
export async function getMarketsTagRows(db: Knex, universe: string): Promise<Array<MarketsTagRow>> {
return db.select([
"markets.category as category",
"markets.openInterest as openInterest",
"markets.tag1 as tag1",
"markets.tag2 as tag2",
"market_state.reportingState as reportingState",
]).from("markets")
示例9:
import Augur from "augur.js";
import { BigNumber } from "bignumber.js";
import * as t from "io-ts";
import * as Knex from "knex";
import * as _ from "lodash";
import { FrozenFunds } from "../../blockchain/log-processors/profit-loss/frozen-funds";
import { BN_WEI_PER_ETHER, ZERO } from "../../constants";
import { Address, MarketsRow, OutcomeParam, ReportingState, SortLimitParams } from "../../types";
import { fixedPointToDecimal, numTicksToTickSize } from "../../utils/convert-fixed-point-to-decimal";
import { Percent, safePercent, Tokens } from "../../utils/dimension-quantity";
import { getRealizedProfitPercent, getTotalProfitPercent, getUnrealizedProfitPercent } from "../../utils/financial-math";
import { getAllOutcomesProfitLoss, ProfitLossResult } from "./get-profit-loss";
export const UserTradingPositionsParamsSpecific = t.type({
universe: t.union([t.string, t.null, t.undefined]),
marketId: t.union([t.string, t.null, t.undefined]),
account: t.union([t.string, t.null, t.undefined]),
outcome: t.union([OutcomeParam, t.number, t.null, t.undefined]),
});
export const UserTradingPositionsParams = t.intersection([
UserTradingPositionsParamsSpecific,
SortLimitParams,
t.partial({
endTime: t.number,
}),
]);
// TradingPosition represents a user's current or historical
// trading activity in one market outcome. See NetPosition.
export interface TradingPosition extends ProfitLossResult, FrozenFunds {
position: string;