普通に 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
=>
やっと通った。。。何したかったんだっけ????