{"action":"created","issue":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/119","repository_url":"https://api.github.com/repos/vitaly-t/pg-promise","labels_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/119/comments","events_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/119/events","html_url":"https://github.com/vitaly-t/pg-promise/issues/119","id":148900255,"number":119,"title":"TypeScript typings have multiple problems","user":{"login":"paavohuhtala","id":803180,"avatar_url":"https://avatars.githubusercontent.com/u/803180?v=3","gravatar_id":"","url":"https://api.github.com/users/paavohuhtala","html_url":"https://github.com/paavohuhtala","followers_url":"https://api.github.com/users/paavohuhtala/followers","following_url":"https://api.github.com/users/paavohuhtala/following{/other_user}","gists_url":"https://api.github.com/users/paavohuhtala/gists{/gist_id}","starred_url":"https://api.github.com/users/paavohuhtala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paavohuhtala/subscriptions","organizations_url":"https://api.github.com/users/paavohuhtala/orgs","repos_url":"https://api.github.com/users/paavohuhtala/repos","events_url":"https://api.github.com/users/paavohuhtala/events{/privacy}","received_events_url":"https://api.github.com/users/paavohuhtala/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/TypeScript","name":"TypeScript","color":"1d76db"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-16T22:48:57Z","updated_at":"2016-04-17T10:21:15Z","closed_at":null,"body":"Hey,\r\n\r\nThanks for implementing TypeScript type definitions for your library. Even though they are very new, they are much more complete than the ones available from DefinitelyTyped.\r\n\r\nHowever, the current version has a few problems that limit their usability.\r\n\r\n* Most importantly, I haven't got them to work yet. I get the following error (which I haven't researched further) when trying to reference them:\r\n```\r\n/node_modules/pg-promise/typescript/pg.ts(136,5): error TS2309: An export assignment cannot be used in a module with other exported elements.\r\n```\r\n* The previous error would probably be solved by using the `pg.d.ts` from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e937b3e64af586d19f2ea29fdf771e9dc4feecc8/pg/pg.d.ts). It's widely used, and well maintained. The usual way is to just `import ... from \"pg\"` in your type definitions, and let the user supply the type definitions for pg via [typings](https://github.com/typings/typings). Using your library via TypeScript would require `typings`, but most things in the TypeScript world do.\r\n* You have to manually reference the typings, either using `tsconfig.json` or via `<reference>` in a source file. This is prone to breaking (when refactoring) and generally not very nice.\r\n  * To fix this you could include a property named `typings` in the package.json pointing to the typings file, so the TypeScript compiler can discover the typings automatically.\r\n    * Your typings should be concatenated into a single file, with the ending `.d.ts`. Additionally, the currently included `.js` files in the typescript directory are not required.\r\n    * Also, the typings shouldn't include any ``/// <reference>`s.\r\n    * [This article tells more about it](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)\r\n  * Alternatively, you could contribute your typings to DefinitelyTyped and/or the typings registry; I'm not sure about the process.\r\n* You should consider exporting some/all of the interfaces, so you could import them directly without having to use `* as `.\r\n* Some functions could be typed a bit better. For instance, the query methods in `IBaseProtocol` should take `string | QueryFile | IPreparedStatement` instead of `any` (you have to write an interface for the last one).\r\n* I really don't like the fact you have to edit a file in the module to change the type of the promise [provider]. You might be able to implement it better via generics, by having a type parameter `TPromise extends Promise<T>`. However, that might be too verbose to implement and/or use. [Default type variables](https://github.com/Microsoft/TypeScript/issues/2175) might help, but they aren't even planned yet for the language.\r\n* Small things\r\n  * Instead of `Array<T>`, you can use `T[]`.\r\n  * You might want to use `PascalCase` for enums, as per the official [TypeScript coding conventions](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines)."},"comment":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/comments/210992870","html_url":"https://github.com/vitaly-t/pg-promise/issues/119#issuecomment-210992870","issue_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/119","id":210992870,"user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"created_at":"2016-04-17T10:21:15Z","updated_at":"2016-04-17T10:21:15Z","body":"Writing TypeScript for pg-promise was my first TypeScript project ever. I was looking for contributors, but nobody wanted to help, so in the end I had to finish it all up by myself. \r\n\r\nThank you for taking time writing it all in detail, I will try to answer it item-by-item...\r\n\r\nFirst, I am surprised you couldn't get it to work, because not only the library itself has lots of tests included (folder `test\\typescript`), but [pg-promise-demo](https://github.com/vitaly-t/pg-promise-demo) uses it entirely, and no problem. Check it out, let me know if you have any problems running that demo.\r\n"}}