4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

firebase functions typescript で @google-cloud/pubsub(@2.5.x) を使う

Posted at

普通に import して使うと ビルドエラー

import { PubSub } from '@google-cloud/pubsub';
# ...

tsc
=> 
node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.d.ts(163,103): error TS2304: Cannot find name 'AsyncIterable'.
node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.d.ts(218,127): error TS2304: Cannot find name 'AsyncIterable'.
node_modules/@google-cloud/pubsub/build/src/v1/publisher_client.d.ts(273,119): error TS2304: Cannot find name 'AsyncIterable'.
node_modules/@google-cloud/pubsub/build/src/v1/subscriber_client.d.ts(202,117): error TS2304: Cannot find name 'AsyncIterable'.
node_modules/@google-cloud/pubsub/build/src/v1/subscriber_client.d.ts(257,109): error TS2304: Cannot find name 'AsyncIterable'.

tsconfig.json を修正

{
  "compilerOptions": {
    ...
+    "lib": ["ESNext.AsyncIterable"]
  },
  ...
}

再ビルド

tsc
=>
node_modules/@google-cloud/pubsub/node_modules/@grpc/grpc-js/build/src/call.d.ts(68,5): error TS2416: Property '_write' in type 'ClientWritableStreamImpl<RequestType>' is not assignable to the same property in base type 'Writable'.
   Type '(chunk: RequestType, encoding: string, cb: WriteCallback) => void' is not assignable to type '(chunk: any, encoding: string, callback: (err?: Error | undefined) => void) => void'.
     Types of parameters 'cb' and 'callback' are incompatible.
       Types of parameters 'err' and 'error' are incompatible.
         Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
           Type 'null' is not assignable to type 'Error | undefined'.

...

nodeのtypeが古いと(8とか?)通らないので追加する

npm install --save-dev @types/node@latest

再ビルド

tsc
=>

やっと通った。。。何したかったんだっけ????

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?