Pg-promise: TypeScript 2.0 support

Created on 14 Oct 2016  ·  26Comments  ·  Source: vitaly-t/pg-promise

npm typings is soon to be deprecated. The new approach is to use something like: npm install @types/pg-promise. This does not work with pg-promise. Likewise, with Typescript 2.0, /// <reference path='../node_modules/pg-promise/typescript/pg-promise' /> doesn't seem to work - tsc says the file isn't found. /// <reference path='../node_modules/pg-promise/typescript/pg-promise.d.ts' />seems is ok, but it generates a ton of errors.

Thanks.

TypeScript improvement

Most helpful comment

@vitaly-t None of it is TypeScript 2.0 specific. All you need to do is add typings or types to package.json and point it to your main .d.ts file while using external modules, and it will "just work". No need to maintain @types or typings.json.

All 26 comments

There is no TypeScript 2.0 support yet. I can't say at this point when it will be added. It may require a lot of re-work, for which I don't have the kind of time at present.

Any contribution for this would be welcome. :wink:

just did a pull request with the @types support -> typescript 2 support - @types #232. We have been using it internally and it's okay.

Tks Vitaly.

@mauriciovigolo do you use a custom promise library or the standard ES6 Promise?

The reason we have an external promise module is to overcome a shortcoming in TypeScript 1.x - lack of parameterized template support. I heard they have fixed it in 2.0.

This is the first thing that will need to be fixed in typescripts. After that, I will consider moving it away from the project and into the definitely typed repository.

I just don't have time for any of that at present. I'm not sure about accepting an incomplete change in TypeScript at the moment.

@vitaly-t, this new version of Typescript really provides support for es2015 declarations as mentioned at the Typescript 2 release notes.
I did in that way for backward compatibility, however if you desire to move on, I also believe that it would be a great idea. In this case, we just have to insert the following in the tsconfig.json:

"compilerOptions": {
    "lib": ["es2015.promise"]
}

We will have to update the Typescript pg-promise documentation. If it's okay I could help you to update it and publish to the definitely typed repository.

Regards,

Please don't move it away from the repo and please do not use @types. This repo could work today by using the native TypeScript node module resolution that's been supported since TypeScript 1.5 and wouldn't require users to do anything (either using Typings or NPM @types). See https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html.

@blakeembrey Could you, please, add what you think should be done, if anything, as opposed to what's not to do.

I haven't had a chance to get into TypeScript 2.0 specifics yet.

@vitaly-t None of it is TypeScript 2.0 specific. All you need to do is add typings or types to package.json and point it to your main .d.ts file while using external modules, and it will "just work". No need to maintain @types or typings.json.

Initial changes have been made (thanks to @xiamx), and released in 5.4.3.

Other things that need to be looked at, in order to finalize the changes:

PR-s are welcome! :wink:

@xiamx Also, should we now just remove file install.js and command "postinstall": "node install.js" from package.json?

should we now just remove file install.js and command "postinstall": "node install.js" from package.json?

yup :)

Cheers!

Accroding to this

Publicize your declaration file
After publishing your declaration file with your package, make sure to add a reference to it in the DefinitelyTyped repo external package list. Adding this will allow search tools to know that your package provides its own declarations.

We still need to add a reference here

We still need to add a reference here

@xiamx if I understand right, this is optional, just to make the package searchable - right?

Yup, though it will help people notice that we distribute our own definition along with the package.

Quite a few still follow the _tsd_, _typings_ guide and will assume that we don't have type definitions if it can't be typings install-ed

Although there are still small details to look into, like updating TypeScript for [pg-minify] and then updating pg-promise accordingly, the main objective here for the library itself has been achieved, so I'm closing the issue.

@xiamx if you can help me with the same type of PR for [pg-minify] as you did for [spex], that'd much appreciated!

Thanks everybody!

@vitaly-t looks like you are already started :)

Thank you! I will try to test this out this weekend.

@xiamx and finished, as far as [pg-minify] goes.

Now the only outstanding piece is [Custom Promises Support].

If you know how to do it - please help out ;)

@vitaly-t, this new version of typescript has a list of built-in API declarations, including es2015.promise - 2.0 release notes.
For using it, the pg-promise user should insert in the project's tsconfig.json file, the required libraries. If the project is using bluebird instead of ES2015 promise library, it would be necessary to install the bluebird definitions, ie.: npm i --save-dev @types/bluebird .
In my opinion you may only need to update your typescript docs about this.

@mauriciovigolo I'm not so sure.

It is just about how to add a custom promise library, but more importantly - how to parameterize the library correctly to use the custom promise library.

If you think you know how to do it right - please, add a PR ;)

I'm re-opening it in the meantime, for easier access to this discussion ;)

Hi, I am trying to use pg-promise in my own typescript project for creating an API. Reading the documentation around typescript says I don't have to install anything else. I figured that VS Code will automatically get the type definitions.

But after installing the latest stable release of the library, I'm still getting the following error:

[ts] Cannot find module 'pg-promise'.

I've tried to manually install types by using npm install --save @types/pg-promise but that seems to be deprecated. I even tried downloading the definition files and using the /// <reference path=""> tag to include them, but that too didn't work.

I'm sure I'm doing something boneheaded here, but I'm not sure how to proceed from here.

Thanks!

@bIgBV are you using TypeScript 2.x?

I am - I brought up the issue because of this. Due to business
circumstances, I no longer needed to use pg-promise. I can resurrect the
code if you wish.

Steve Buschman
978-254-1114

On Dec 30, 2016 7:06 PM, "Vitaly Tomilov" notifications@github.com wrote:

@bIgBV https://github.com/bIgBV are you using TypeScript 2?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/vitaly-t/pg-promise/issues/220#issuecomment-269837047,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANRyxzXNP5IWb0n186ngbgUhfjoq8P5qks5rNZyRgaJpZM4KWffE
.

@mauriciovigolo would you be able to comment on this? I'm a little lost as to what it wouldn't work as reported above...

@sbusch99 were you able t sort this out eventually?


Ideally, if there are still issues, it would be better to close this one and open a new one specific to the problem.

@bIgBV and @sbusch99

Guys, if you are still experiencing problems with the TypeScript support, please open a separate issue specific to your problem, it will be easier to track.

I'm closing this one, because general TypeScript support is finished, and I see no problems there as of yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

calibermind picture calibermind  ·  3Comments

hawkeye64 picture hawkeye64  ·  4Comments

leemhenson picture leemhenson  ·  5Comments

ghost picture ghost  ·  3Comments

jabooth picture jabooth  ·  4Comments