还没有@google-cloud/logging
. 所以你需要提供一些!与此同时,你可以做
const Logging: any = require('@google-cloud/logging')
如果您已@types/node
安装并以 nodejs为目标,或者您以浏览器为目标但使用"moduleResolution": "CommonJS"
(您还需要提供 node typefs)。
否则,您可以使用
import * as Logging from '@google-cloud/logging'
但在这种情况下,您需要声明此模块的类型
// logging.d.ts
declare module '@google-cloud/logging' {
interface LogConfig {
removeCircular: boolean
}
class Entry {
metadata: object
data: object
constructor (metadata: object | null | undefined, data: object | string)
constructor (data: object | string)
toJSON (options?: LogConfig): any
}
interface WriteOptions {
gaxOptions: object
labels: object[]
resource: object
}
type LogWriteCallback = (err: Error | null, apiResponse: object) => void
type DeleteLogCallback = (err: Error | null, apiResponse: object) => void
type LogWriteResponse = object[]
type DeleteLogResponse = object[]
type EntryArg = Entry | Entry[]
class Log {
constructor (logging: Logging, name: string, options: LogConfig)
alert (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
critical (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
debug (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
emergency (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
info (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
notice (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
warning (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
error (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
write (entry: EntryArg, options?: WriteOptions, callback?: LogWriteCallback): Promise<LogWriteResponse>
delete (gaxOptions: object): Promise<DeleteLogResponse>
delete (gaxOptions: object, callback?: DeleteLogCallback): Promise<DeleteLogResponse>
delete (callback?: DeleteLogCallback): Promise<DeleteLogResponse>
}
interface ClientConfig {
projectId?: string
keyFilename?: string
email?: string
credentials?: {
client_email: string
private_key: string
}
autoRetry?: boolean
maxRetries?: number
promise?: Function
}
class Logging {
constructor (options: ClientConfig)
log (name: string, options?: LogConfig): Log
entry (resource: object | string | null | undefined, data: object | string): Entry
}
export = Logging
}
这个定义只是一个草稿,缺少很多功能,但我想这是必要的第一步:-)