TypeScript: Jimp types are not corresponding to Jimp implementation
See original GitHub issueExpected Behavior
When importing Jimp as described in the doc for a TypeScript project:
import Jimp from 'jimp'
I should be able to use Jimp directly as is:
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
Current Behavior
The compile step is OK, but there is runtime error saying:
TypeError: Cannot read property 'read' of undefined
If I use the require-like import syntax:
import * as Jimp from 'jimp'
and use Jimp as below:
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
I then have a compile error saying:
Property 'read' does not exist on type 'typeof import("/path/to/node_modules/jimp/types/ts3.1/index")'
If I disable manually type checking for Jimp:
// @ts-ignore
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
There is no runtime error and Jimp works as expected.
Failure Information (for bugs)
Context
- Jimp Version: 0.8.4
- Operating System: macOS 10.15 Catalina
- Node version: 10.16.3
- NPM Version: 6.11.3
- TypeScript Version: 3.6.3
Workaround
To use Jimp with types information, I have to import the types separately and bind them to the classic require syntax:
import Jimp from 'jimp'
// tslint:disable-next-line: no-var-requires
const jimp: Jimp = require('jimp')
And then, use “jimp” instead of “Jimp”:
jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:26 (15 by maintainers)
Top Results From Across the Web
Jimp - npm
An image processing library for Node written entirely in JavaScript, with zero native dependencies. The default jimp configuration. Supported ...
Read more >Jimp: image processing fail on module usage - Stack Overflow
I'm using import * as Jimp from 'jimp' and that's working fine. I'm using webpack, but it should not be different in TypeScript/Angular....
Read more >Documentation - TypeScript 4.9
In the editor, when running a go-to-definition on the return keyword, TypeScript will now jump you to the top of the corresponding function....
Read more >TypeScript | IntelliJ IDEA Documentation - JetBrains
IntelliJ IDEA supports developing, running, and debugging TypeScript source code. IntelliJ IDEA recognizes .ts and .tsx files and provides full range of ...
Read more >Code Navigation in Visual Studio Code
Tip: You can open any file by its name when you type Ctrl+P (Quick Open). ... Tip: You can jump to the definition...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are y’all able to test against
0.9.2
stable release. There was some work done to improve TS stability and should fix everyone’s issues with typings (if you were one of the ones that had to revert to 0.6.4, this includes you). Please test against and confirm/deny crosses fingersOh gotcha I see what you’re up to! Love what you’ve been able to do thus far. If we’re able to get some stuff into our type tests, I’d appreciate that as well! I think once you have more tweaks (as you’d mentioned, I didn’t have any notes at a first glance), I’ll be able to review the PR today and we can probably get it moved forward.
Thanks so much for jumping in and helping! 😄