node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

There is an intention to make an official @types for the API?

Open drachehavoc opened this issue 6 years ago • 12 comments

Nowadays TypeScript is a very popular way to write robust JavaScript, I am an adept of this superset and am in a project that needs to connect to MySQL.

Going straight to the point: 1 - exsite an official @types npm for mysql2, which does not use the old typings? 2 - is there intention of creation?

drachehavoc avatar Apr 22 '19 21:04 drachehavoc

I found this types https://github.com/types/mysql2, but the npm install is not working properly, so I manually downloaded it and added it to my project.

It would be nice if the command npm i --save-dev @type/mysql2 work

drachehavoc avatar Apr 22 '19 22:04 drachehavoc

Hi @drachehavoc , yes agree with you, would be good to improve typescript experience with node-mysql2 Would you be able to help with this?

sidorares avatar Apr 23 '19 00:04 sidorares

Sure! I will write some d.ts and share with you in next days.

I will be happy to help. ^^

drachehavoc avatar Apr 24 '19 23:04 drachehavoc

honestly, it would be better to have the typescript definition available as part of mysql2. Quite easy to do: you just need one file '.d.ts' and a config entry in package.json. Of course this implies that the definitions are maintained. However I don't think that the public API is changing that much and therefore, after the initial load, changes should be minimal.

FredericLatour avatar Jun 18 '19 09:06 FredericLatour

@FredericLatour I'm happy to bundle it with the package and maintain. Do you know any tools that might assist in automatic "typings match what's in the code" check? Can you volunteer to add typings here?

sidorares avatar Jun 18 '19 23:06 sidorares

@sidorares Great to hear.

Why not starting from the existing type definition (the one I'm using) available here: https://github.com/types/mysql2 (please note that this is not the DefinetelyTyped repo which make it difficult for people to know it exists). I can see that there was already a discussion on the possibility to include it in the repository.

Best approach if you ask me is that you include the files without waiting for a PR and then if something is missing people can PR to add/correct the definition in the repo.

FredericLatour avatar Jun 19 '19 10:06 FredericLatour

@drachehavoc Any progress on this? If you have one version, maybe it's a good idea to make a PR first. So that we could improve it.

mapleeit avatar Jul 19 '19 06:07 mapleeit

Here to show support. +1 to this. Currently having to write my own interfaces for simple things.

RShadowhand avatar Sep 10 '19 15:09 RShadowhand

Came here as well for the typings..

kirillgroshkov avatar Sep 30 '19 15:09 kirillgroshkov

Adding manually the following entry in the package.json worked for me:

{
  ...
  "devDependencies": {
    ...
    "@types/mysql2": "git+https://[email protected]/types/mysql2.git"
  }
}

But I agree that it would be better if the command npm i -D @type/mysql2 worked.

Cl00e9ment avatar Apr 08 '20 21:04 Cl00e9ment

thumbs up for making the @types prefix official which can standardize the package name to remove confusion while installing type def like me. There was an issue opened (but now closed) regarding the same matter. It is just so sad that the maintainer did not do anything about it.

bentong95923 avatar Dec 19 '20 04:12 bentong95923

in the latest version the tyepscript types are shipped as part of the npm package, so no need for the @types or @type/mysql2 anymore

larshp avatar Dec 20 '20 09:12 larshp

You can look at typings/mysql for the MySQL2 types and its documentation in documentation/en/TypeScript-Examples.md.

wellwelwel avatar Jul 09 '23 13:07 wellwelwel