本文整理匯總了TypeScript中io-ts.partial函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript partial函數的具體用法?TypeScript partial怎麽用?TypeScript partial使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了partial函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
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),
});
export interface PartialInfraSourceConfiguration
extends runtimeTypes.TypeOf<typeof PartialInfraSourceConfigurationRuntimeType> {}
export const InfraSavedSourceConfigurationRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
id: runtimeTypes.string,
attributes: PartialInfraSourceConfigurationRuntimeType,
}),
runtimeTypes.partial({
version: runtimeTypes.string,
updated_at: TimestampFromString,
}),
]);
示例2:
import * as t from "io-ts";
import * as Knex from "knex";
import * as _ from "lodash";
import Augur from "augur.js";
import { Address, MarketsRowWithTime, Payout, UIStakeInfo, PayoutRow, StakeDetails, ReportingState } from "../../types";
import { getMarketsWithReportingState, normalizePayouts, uiStakeInfoToFixed, groupByAndSum } from "./database";
import { BigNumber } from "bignumber.js";
import { QueryBuilder } from "knex";
import { ZERO } from "../../constants";
export const DisputeInfoParams = t.intersection([
t.type({
marketIds: t.array(t.string),
}),
t.partial({account: t.string}),
]);
interface DisputeRound {
marketId: Address;
disputeRound: number;
}
interface DisputesResult {
markets: Array<MarketsRowWithTime>;
stakesCompleted: Array<StakeRow>;
stakesCurrent: Array<ActiveCrowdsourcer>;
accountStakesCompleted: Array<StakeRow>;
accountStakesCurrent: Array<StakeRow>;
payouts: Array<PayoutRow<BigNumber>>;
disputeRound: Array<DisputeRound>;
}
示例3:
}
export const OutcomeParam = t.keyof({
0: null,
1: null,
2: null,
3: null,
4: null,
5: null,
6: null,
7: null,
});
export const SortLimitParams = t.partial({
sortBy: t.union([t.string, t.null, t.undefined]),
isSortDescending: t.union([t.boolean, t.null, t.undefined]),
limit: t.union([t.number, t.null, t.undefined]),
offset: t.union([t.number, t.null, t.undefined]),
});
export interface SortLimit {
sortBy: string|null|undefined;
isSortDescending: boolean|null|undefined;
limit: number|null|undefined;
offset: number|null|undefined;
}
export interface GetMarketInfoRequest {
jsonrpc: string;
id: string|number;
method: string;
params: {
示例4:
// tslint:disable-next-line no-empty-interface
export interface CreateGameRequest extends t.TypeOf<typeof CreateGameRequestType> {}
const PositionType = t.exact(t.type({
row: t.string,
col: t.string,
}))
export const MoveRequestType = t.exact(t.intersection([
t.type({
from: PositionType,
dest: PositionType,
}),
t.partial({
promotionType: t.string,
}),
]))
// tslint:disable-next-line no-empty-interface
export interface MoveRequest extends t.TypeOf<typeof MoveRequestType> {}
export interface ApiUser {
id: string
name: string
email: string
}
export interface ApiGameInfo {
id: string
title: string
示例5:
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;
}
// AggregatedTradingPosition is an aggregation of TradingPosition for some
// scope, eg. an aggregation of all TradingPosition in a user's portfolio.
export interface AggregatedTradingPosition extends Pick<ProfitLossResult,
"realized" | "unrealized" | "total" | "unrealizedCost" | "realizedCost" | "totalCost" | "realizedPercent" |
"unrealizedPercent" | "totalPercent" | "unrealizedRevenue" | "unrealizedRevenue24hAgo" | "unrealizedRevenue24hChangePercent"
>, FrozenFunds { }
示例6:
export const plugin = t.type({});
export type Plugin = t.TypeOf<typeof plugin>;
export const rc = t.partial({
plugins: t.array(t.union([t.string, plugin])),
dir: t.string,
mocha: t.partial({
requires: t.array(t.string),
ui: t.string,
reporter: t.string
}),
webpack: t.partial({
modifier: t.Function,
entry: t.union([
t.string,
t.dictionary(t.string, t.string),
t.array(t.string)
]),
output: t.type({
path: t.string,
filename: t.union([t.Function, t.string])
})
})
});
type RCBase = t.TypeOf<typeof rc>;
type WebpackBase = RCBase['webpack'];
示例7: moment
const momentValue = moment(stringInput);
return momentValue.isValid()
? runtimeTypes.success(momentValue.valueOf())
: runtimeTypes.failure(stringInput, context);
}),
output => new Date(output).toISOString()
);
/**
* Stored source configuration as read from and written to saved objects
*/
const SavedSourceConfigurationFieldsRuntimeType = runtimeTypes.partial({
container: runtimeTypes.string,
host: runtimeTypes.string,
pod: runtimeTypes.string,
tiebreaker: runtimeTypes.string,
timestamp: runtimeTypes.string,
});
export const SavedSourceConfigurationRuntimeType = runtimeTypes.partial({
name: runtimeTypes.string,
description: runtimeTypes.string,
metricAlias: runtimeTypes.string,
logAlias: runtimeTypes.string,
fields: SavedSourceConfigurationFieldsRuntimeType,
});
export interface InfraSavedSourceConfiguration
extends runtimeTypes.TypeOf<typeof SavedSourceConfigurationRuntimeType> {}
示例8: useAppContext
// Typed app routing via brilliant gcanti/io-ts.
// Soon in Next.js: https://twitter.com/timneutkens/status/1109092151907045376
const AppHrefIO = t.union([
t.type({ pathname: t.literal('/') }),
t.type({ pathname: t.literal('/me') }),
t.type({ pathname: t.literal('https://twitter.com/steida') }),
t.type({
pathname: t.literal('/web'),
query: t.type({ id: t.string }),
}),
// https://github.com/gcanti/io-ts#mixing-required-and-optional-props
t.intersection([
t.type({ pathname: t.literal('/signin') }),
t.partial({ query: t.type({ redirectUrl: t.string }) }),
]),
]);
export type AppHref = t.TypeOf<typeof AppHrefIO>;
export const useAppHref = () => {
const { router } = useAppContext();
// This should be memoized globally. In serverless, it means per request :-)
const current = useMemo<AppHref | undefined>(() => {
let maybeAppHref: AppHref | undefined;
const routerAppHref = { pathname: router.pathname, query: router.query };
AppHrefIO.decode(routerAppHref).fold(
_errors => {}, // No need to report unmatched app href.
value => {
示例9:
import * as runtimeTypes from 'io-ts';
import { unionWithNullType } from '../framework';
/*
* Note Types
*/
export const SavedPinnedEventRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
timelineId: runtimeTypes.string,
eventId: runtimeTypes.string,
}),
runtimeTypes.partial({
created: runtimeTypes.number,
createdBy: runtimeTypes.string,
updated: runtimeTypes.number,
updatedBy: runtimeTypes.string,
}),
]);
export interface SavedPinnedEvent extends runtimeTypes.TypeOf<typeof SavedPinnedEventRuntimeType> {}
/**
* Note Saved object type with metadata
*/
export const PinnedEventSavedObjectRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
id: runtimeTypes.string,
attributes: SavedPinnedEventRuntimeType,
version: runtimeTypes.string,
示例10: unionWithNullType
import * as runtimeTypes from 'io-ts';
import { unionWithNullType } from '../framework';
import { NoteSavedObjectToReturnRuntimeType } from '../note/types';
import { PinnedEventToReturnSavedObjectRuntimeType } from '../pinned_event/types';
/*
* ColumnHeader Types
*/
const SavedColumnHeaderRuntimeType = runtimeTypes.partial({
aggregatable: unionWithNullType(runtimeTypes.boolean),
category: unionWithNullType(runtimeTypes.string),
columnHeaderType: unionWithNullType(runtimeTypes.string),
description: unionWithNullType(runtimeTypes.string),
example: unionWithNullType(runtimeTypes.string),
indexes: unionWithNullType(runtimeTypes.array(runtimeTypes.string)),
id: unionWithNullType(runtimeTypes.string),
name: unionWithNullType(runtimeTypes.string),
placeholder: unionWithNullType(runtimeTypes.string),
searchable: unionWithNullType(runtimeTypes.boolean),
type: unionWithNullType(runtimeTypes.string),
});
/*
* DataProvider Types
*/
const SavedDataProviderQueryMatchBasicRuntimeType = runtimeTypes.partial({
field: unionWithNullType(runtimeTypes.string),
displayField: unionWithNullType(runtimeTypes.string),
value: unionWithNullType(runtimeTypes.string),
displayValue: unionWithNullType(runtimeTypes.string),