New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Types #496
base: master
Are you sure you want to change the base?
Adding Types #496
Conversation
Hmm. So I see that this adds declarations of the functions that jsdiff exports but all parameters and return types are just set to I'm not too sure what the best way to do that is, though. Probably I should port the whole library to TypeScript, adding types to function signatures as I go, and change its build process to compile from TypeScript? |
Another way would be to add jsdoc comments for the exported functions - IIRC those get picked up by tsc and used in the generated declaration files. |
Ah, nice! That does indeed seem to work and I guess it'll do the trick. |
Yeah, I understand that this is not ideal @ExplodingCabbage - This is just a way of making sure that every jsdiff version has up-to-date method information to be used in typescript. The issue that motivated me was not being able to use a method that existed on the latest version of jsdiff because the type was not updated on https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff. That being said, @ehoogeveen-medweb suggestion is far better than porting the whole stuff lol |
Well, I don't know about better as I do like TypeScript a lot, but it's certainly a lot less work ;) |
Okay, coming back to this after a break... I think porting to TypeScript is probably actually no more work than adding JSDoc comments would be. One problem with adding JSDoc comments is that some TypeScript concepts don't quite have clean analogues in JSDoc. For instance, the I'm gonna have a stab at actually porting everything to TypeScript and using Babel's preset-typescript to transpile to JavaScript (as seems to be the recommendation at https://www.typescriptlang.org/docs/handbook/babel-with-typescript.html if you need a build pipeline anyway); I'm hoping that besides actually sprinkling TypeScript types into all the function definitions, there's not gonna be much work involved in this beyond adding a few lines to the Babel config. Will see if that hope is proved accurate... |
By the way, one thing that might help in this process is https://arethetypeswrong.github.io or https://www.npmjs.com/package/@arethetypeswrong/cli (right now there are no types, but once there are, getting CJS and ESM to both work can be tricky). |
Adding TS types.