-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Improve TypeScript declarations file #660
Conversation
Addresses but does not fully close #581 Proper way to import is now `import * as X from 'jimp'` wherein X can be whatever the end-user wants, in most cases `Jimp`.
@hipstersmoothie @pndewit tagging you since you're on the issue it addresses |
packages/jimp/jimp.d.ts
Outdated
declare module 'jimp' { | ||
export = Jimp.Jimp; | ||
} | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your concern, but please read the corresponding issue as well. Technically the line is not needed as the compiler does not actually compile the type declarations. The ignore is exclusively for those people who open the file in their IDE which would report the structure as invalid. It is however, very much valid; if it wouldn't be then compiling would crash.
I have losely based this on knowledge gained from analyzing other declarations files, primarily @types/better-sqlite3. Using this formatting for declaration file allows for `import * as Jimp from 'jimp'` importing which is a proper way when using TypeScript as it primarily recommends ES6 imports. It will require setting the `allowSyntheticDefaultImports` compiler option to `true`, however this is a very small issue as many packages on npm (including aforementioned better-sqlite3) require this. - Like previous commit this ensures we no longer need to use `import Jimp = require('jimp'). As has been agreed upon, using `require` when working with ES6 modules is just wrong in code style. - Unlike previous commit no more ts-ignore, yay! - It is maintainable. New types or interface come at the bottom and any new or modifications to functions and constants go in the topmost interface. We'll never have to touch the declared const or the export.
@DanielRosenwasser @hipstersmoothie I've reworked it so it no longer requires the I have losely based this on knowledge gained from analyzing other declarations files, primarily
Lastly, I would really appreciate a new version to be pushed to npm if you guys decide to merge this. Due to your building setup I can't just |
Oh and one final note, if you guys decide to merge this I think #581 can be closed since the importing and exporting should be entirely fixed but I'll let that upon your judgement. |
@favna I will release once @DanielRosenwasser gives a 👍 |
Okay, I think that this change is appropriate. Users can use import jimp = require("jimp") to import the module. Alternatively, if they have import jimp from "jimp"; |
For the record, because Jimp is callable, |
@favna can you add @DanielRosenwasser usage comment to the docs in the "jimp" package readme? After that I'll get it merged and released. |
* Improve TypeScript declarations file Addresses but does not fully close #581 Proper way to import is now `import * as X from 'jimp'` wherein X can be whatever the end-user wants, in most cases `Jimp`. * Truly resolve declarations file I have losely based this on knowledge gained from analyzing other declarations files, primarily @types/better-sqlite3. Using this formatting for declaration file allows for `import * as Jimp from 'jimp'` importing which is a proper way when using TypeScript as it primarily recommends ES6 imports. It will require setting the `allowSyntheticDefaultImports` compiler option to `true`, however this is a very small issue as many packages on npm (including aforementioned better-sqlite3) require this. - Like previous commit this ensures we no longer need to use `import Jimp = require('jimp'). As has been agreed upon, using `require` when working with ES6 modules is just wrong in code style. - Unlike previous commit no more ts-ignore, yay! - It is maintainable. New types or interface come at the bottom and any new or modifications to functions and constants go in the topmost interface. We'll never have to touch the declared const or the export.
Ow.. I see you merged already. Sorry I didn't add the usage doc to the readme yet. Long work days means I only just got home and you guys commented at my 2AM :\ I'll add the usage docs right now and create a new PR I guess. |
sorry! i merged then realized you hadn't done it. I'm using it in the CLI package. Releasing now in 0.6.0. The only thing that seems to not quite work right is the font types. In some places I was using Jimp.Font and had to switch to any |
What's Changing and Why
Addresses but does not fully close #581
Proper way to import is now
import * as X from 'jimp'
wherein X can bewhatever the end-user wants, in most cases
Jimp
.As stated on the aforementioned issue another PR might come with a more thorough fix not requiring
// @ts-ignore
What else might be affected
Method of importing with TypeScript, possible requires doc updates.
Tasks
jimp.d.ts