本文整理匯總了TypeScript中is.array函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript array函數的具體用法?TypeScript array怎麽用?TypeScript array使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了array函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
(BigQuery as any).getType_ = function(value) {
let typeName;
if (value instanceof (BigQuery as any).date) {
typeName = 'DATE';
} else if (value instanceof (BigQuery as any).datetime) {
typeName = 'DATETIME';
} else if (value instanceof (BigQuery as any).time) {
typeName = 'TIME';
} else if (value instanceof (BigQuery as any).timestamp) {
typeName = 'TIMESTAMP';
} else if (value instanceof Buffer) {
typeName = 'BYTES';
} else if (value instanceof Big) {
typeName = 'NUMERIC';
} else if (is.array(value)) {
return {
type: 'ARRAY',
arrayType: (BigQuery as any).getType_(value[0]),
};
} else if (is.bool(value)) {
typeName = 'BOOL';
} else if (is.number(value)) {
typeName = value % 1 === 0 ? 'INT64' : 'FLOAT64';
} else if (is.object(value)) {
return {
type: 'STRUCT',
structTypes: Object.keys(value).map(function(prop) {
return {
name: prop,
type: (BigQuery as any).getType_(value[prop]),
};
}),
};
} else if (is.string(value)) {
typeName = 'STRING';
}
if (!typeName) {
throw new Error(
[
'This value could not be translated to a BigQuery data type.',
value,
].join('\n')
);
}
return {
type: typeName,
};
};
示例2: is
export function is(value: any): value is LocalizeInfo {
let candidate = value as LocalizeInfo;
return Is.defined(candidate) && Is.string(candidate.key) && (Is.undef(candidate.comment) || (Is.array(candidate.comment) && candidate.comment.every(element => Is.string(element))));
}