本文整理汇总了TypeScript中tcomb.maybe函数的典型用法代码示例。如果您正苦于以下问题:TypeScript maybe函数的具体用法?TypeScript maybe怎么用?TypeScript maybe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maybe函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const BaseInlineQuery = function <T>(props: any, name: string = 'Unknown') {
return t.struct<T>(
Object.assign(
{},
{
type: t.String,
id: t.String,
reply_markup: t.maybe(k.InlineKeyboardMarkup),
input_message_content: t.maybe(InputMessageContent)
},
props),
name)
}
示例2:
import * as t from 'tcomb'
import * as m from './multimedia-types'
export const InputFile = t.Any
export interface TcombInputFile {}
export const User = t.struct<TcombUser>({
id: t.Number,
first_name: t.String,
last_name: t.maybe(t.String),
username: t.maybe(t.String)
})
export interface TcombUser {
id: number
first_name: string
last_name?: string
username?: string
}
export const ChatMember = t.struct<TcombChatMember>({
user: User,
status: t.enums.of([
'creator',
'administrator',
'member',
'left',
'kicked'
])
})
export interface TcombChatMember {
user: TcombUser,
示例3: it
import { parse as _parse, stringify as _stringify } from '../src/parser';
import * as t from 'tcomb';
type S = {
view: string;
numb: number;
bool: boolean;
optNumb?: number;
optBool?: boolean;
};
const ST = t.interface<S>({
view: t.String,
numb: t.Number,
bool: t.Boolean,
optNumb: t.maybe(t.Number),
optBool: t.maybe(t.Boolean)
});
const parse = _parse(ST);
const stringify = _stringify(ST);
describe('parse', () => {
it('should parse numbers', () => {
expect(parse({ view: 'foo', numb: '4' })).toMatchSnapshot();
});
it('should parse optional numbers', () => {
expect(parse({ view: 'foo', optNumb: '4' })).toMatchSnapshot();
});
it('should parse booleans', () => {
expect(parse({ view: 'foo', bool: 'true' })).toMatchSnapshot();
});
it('should parse optional booleans', () => {
示例4:
import * as t from 'tcomb'
import { TcombCallbackGame, CallbackGame } from './types'
export const KeyboardButton = t.struct<TcombKeyboardButton>({
text: t.String,
request_contact: t.maybe(t.Boolean),
request_location: t.maybe(t.Boolean)
})
export interface TcombKeyboardButton {
text: string
request_contact?: boolean
request_location?: boolean
}
export const ReplyKeyboardMarkup = t.struct<TcombReplyKeyboardMarkup>({
keyboard: t.list(t.list(KeyboardButton)),
resize_keyboard: t.maybe(t.Boolean),
one_time_keyboard: t.maybe(t.Boolean),
selective: t.maybe(t.Boolean)
})
export interface TcombReplyKeyboardMarkup {
keyboard: TcombKeyboardButton[][]
resize_keyboard?: boolean
one_time_keyboard?: boolean
selective?: boolean
}
export const ReplyKeyboardRemove = t.struct<TcombReplyKeyboardRemove>({
hide_keyboard: t.Boolean,
selective: t.maybe(t.Boolean)
})
示例5:
import * as t from 'tcomb'
export const PhotoSize = t.struct<TcombPhotoSize>({
file_id: t.String,
width: t.Number,
height: t.Number,
file_size: t.maybe(t.Number)
})
export interface TcombPhotoSize {
file_id: string
width: number
height: number
file_size?: number
}
export const Audio = t.struct<TcombAudio>({
file_id: t.String,
duration: t.Number,
performer: t.maybe(t.String),
title: t.maybe(t.String),
mime_type: t.maybe(t.String),
file_size: t.maybe(t.Number)
})
export interface TcombAudio {
file_id: string
duration: number
performer?: string
title: string
mime_type?: string
file_size?: number
}