Currently blocked on https://github.com/googleapis/gapic-generator/issues/2054
The first thought I see a morden js library: why not in TypeScript?
I am really confused, https://github.com/google/google-api-nodejs-client#typescript is written in TypeScript yet it is the _older_ library? All I want to do is pull from pubsub in my App Engine Node app.
I think I'll stick to the older library with the typedefs despite what the documentation advises.
In the meantime is there a recommended way to import and use @google-cloud/pubsub with TypeScript?
I'm using typescript definitions from @types/google-cloud__pubsub
Below makes ts complain -
"Only a void function can be called with the 'new' keyword."
"New expression whose target lacks a construct signature, implicitly has 'any' type.
import PubSub = require('@google-cloud/pubsub');
let pubsub: PubSub.PubSub = new PubSub();
Below compiles but then the JS doesn't work -
"Class constructor PubSub cannot be invoked without 'new'"
import PubSub = require('@google-cloud/pubsub');
let pubsub: PubSub.PubSub = PubSub();
So I'm doing this for now...
import PubSub = require('@google-cloud/pubsub');
let pubsub: PubSub.PubSub = new (PubSub as any)();
let pubsub: PubSub.PubSub = new (PubSub as any)();
Looks like the syntax has changed again. Now we have to do
import PubSub = require("@google-cloud/pubsub");
const pubSub: PubSub.PubSub = new (PubSub as any).PubSub();
Is there any activity on this? The current pubsub library release is nearly impossible to use from TypeScript, since it doesn't ship its own types info, and the DefinitelyTyped info is sufficiently out of date that the only methods it acknowledges are available for publishing no longer exist, and the only methods actually available for publishing aren't in the DefinitelyTyped package.
There's been a ton of activity! You can see a few active PRs here:
https://github.com/googleapis/nodejs-pubsub/pulls
As it turns out, this is a pretty large code base so we can't tackle this all at once.
This is done 馃 Will be in the next release.
yay! @JustinBeckwith what's the release cycle like? Eagerly waiting for the new changes.
@callmehiphop will be cooking up one v soon :)
I'm not seeing the types in this latest release (assuming they were supposed to be added..)
I second that. I ended up looking in the node_modules directory to see what was installed and could not find ./build/src/index.d.ts They aren't in the git repo either鈥揳re they autogenerated in the build step?
Think they just forgot to remove the exclusion
@JustinBeckwith Can you please push out a bugfix release now that the typescript declaration files are properly generated? As this is not yet in the latest v0.25.0 release. I am eagerly waiting to use this with typescript.
@mjaros there are a couple of pending PRs I'd like to merge first, but I will try and cut a new release today. Although it will likely be a new minor.
@mjaros v0.26.0 was just released and shipped with types! Let us know if you run into any problems upgrading
topic.exists() doesn't work in typescript, because the exported types claim the callback parameter is mandatory and the return type is void -- i.e. the types don't reflect that method being promisfied:
https://github.com/googleapis/nodejs-pubsub/blob/cbb60c99a431b2e37f786fcf14c4ded573376505/src/topic.ts#L305
@mgabeler-lee-6rs yeah, it looks like some of our signatures aren't quite right. I'm actively working on it and will hopefully have some fixes released soonish.
I am trying to use PublisherClient like this in TypeScript.
const pubsub = new v1.PublisherClient(credential);
But got his Property 'PublisherClient' does not exist on type 'typeof import ....
Greetings @gaohannk! Can you open a new issue? Thanks!
Most helpful comment
In the meantime is there a recommended way to import and use @google-cloud/pubsub with TypeScript?
I'm using typescript definitions from @types/google-cloud__pubsub
Below makes ts complain -
"Only a void function can be called with the 'new' keyword."
"New expression whose target lacks a construct signature, implicitly has 'any' type.
Below compiles but then the JS doesn't work -
"Class constructor PubSub cannot be invoked without 'new'"
So I'm doing this for now...