Type-Script가 아닌 모듈을 TypeScript 프로젝트로 가져 오려고합니다.Typescript import @ google-cloud/pubsub
이 프로젝트에는 자체 선언이나 @types 선언이 없으므로 모듈에 대한 자체 선언을 만들었습니다. 내가 선언 파일에 모듈을 선언 할 때, 나는 다음과 같은 오류 얻을 :
import stream from 'stream'
import events from 'events'
interface ConfigurationObject extends Object {
projectId?: string
keyFilename?: string
email?: string
credentials?: CredentialsObject
autoRetry?: boolean
maxRetries?: number
promise?: Function
}
interface CredentialsObject extends Object {
client_email?: string
private_key?: string
}
interface QueryOptions extends Object {
autoPaginate?: boolean
maxApiCalls?: number
maxResults?: number
pageSize?: number
pageToken?: string
}
interface SnapshotQueryOptions extends QueryOptions { }
interface TopicsQueryOptions extends Object { }
interface SubscriptionQueryOptions extends Object {
topic?: string
}
interface SubscribeOptions extends Object {
ackDeadlineSeconds: number
autoAck: boolean
encoding: string
interval: number
maxInProgress: number
pushEndpoint: string
timeout: number
}
interface SubscriptionOptions extends Object {
autoAck?: boolean
encoding?: string
interval?: number
maxInProgress?: number
timeout?: number
}
interface SubscriptionObject extends Object {
name: string
topic: string
pushConfig: PushConfigObject
ackDeadlineSeconds: number
}
interface PushConfigObject extends Object {
pushEndpoint: string
attributes: {
[key: string]: string
}
}
interface TopicObject extends Object {
name: string
}
interface SnapshotObject extends Object {
name: string
}
interface Message {
id: string
ackId: string
data: any
attributes: any
timestamp: number
ack(callback: Function): void
skip(): void
}
declare type ApiCallbackFunction<T> = (err: Error | null, data: T, apiResponse: any) => void
declare type CallbackFunction<T> = (err: Error | null, data: T) => void
declare type ApiPromiseResult<T> = [T, any]
declare class Subscription extends events.EventEmitter {
ack(
ackIds: string | string[],
options?: {
timeout: number
},
callback?:() => void
): Promise<void> | void
create(
options?: SubscribeOptions,
callback?: ApiCallbackFunction<SubscriptionObject>
): Promise<ApiPromiseResult<SubscriptionObject>> | void
createSnapshot(
name: string,
callback?: ApiCallbackFunction<SnapshotObject>
): Promise<ApiPromiseResult<SnapshotObject>> | void
}
declare class PubSub {
constructor(
config: ConfigurationObject
)
createTopic(
name: string,
callback?: ApiCallbackFunction<TopicObject>
): Promise<ApiPromiseResult<TopicObject>> | void
getSnapshots(
options?: SnapshotQueryOptions,
callback?: CallbackFunction<SnapshotObject[]>
): Promise<any[]> | void
getSnapshotsStream(
options?: SnapshotQueryOptions
): stream.Readable
getSubscriptions(
options?: SubscriptionQueryOptions,
callback?: ApiCallbackFunction<SubscriptionObject[]>
): Promise<ApiPromiseResult<SubscriptionObject[]>> | void
getSubscriptionsStream(
options?: SubscriptionQueryOptions
): stream.Readable
getTopics(
options?: TopicsQueryOptions,
callback?: ApiCallbackFunction<TopicObject[]>
): Promise<ApiPromiseResult<TopicObject[]>> | void
getTopicsStream(
options?: TopicsQueryOptions
): stream.Readable
snapshot(
name: string
): any
subscribe(
topic: TopicObject | string,
subName?: stream,
options?: SubscribeOptions,
callback?: ApiCallbackFunction<SubscriptionObject>
): Promise<ApiPromiseResult<SubscriptionObject>> | void
subscription(
name?: string,
options?: SubscriptionOptions
): void
topic(
name: string
): TopicObject
}
declare module '@google-cloud/pubsub' {
export = PubSub
}
고마워요! 다른 가져 오기 구조를 사용하여 "@ google-cloud/pubsub"패키지를 가져와야하는 유일한 차이점 만 설명하면 효과적입니다. 이제 다음과 같이 보입니다 :'import PubSub = require ('@ google-cloud/pubsub')'. – Siggy