question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating an image compiles with an error in TypeScript

See original GitHub issue

I’m trying to use Jimp with TypeScript in a following manner:

import * as Jimp from "jimp";
let image = new Jimp(256, 256, function (err, image) {
});

It produces the following errors:

severity: 'Error'
message: 'Only a void function can be called with the 'new' keyword.'
at: '2,13'
source: 'ts'
code: '2350'

severity: 'Error'
message: ''new' expression, whose target lacks a construct signature, implicitly has an 'any' type.'
at: '2,13'
source: 'ts'
code: '7009'

However, when I ignore the TypeScript compile-time errors and debug the result, it works just as expected, i.e. the image is created successfully. So it looks like we have a problem with jimp.d.ts. In fact, it describes the corresponding constructor not as a constructor, but as a regular function.

My main hypothesis is that d.ts file was prepared for an older version of TypeScript and uses different ways to describe Jimp class (a function with a prototype). However, I’m new to TypeScript, so I may miss something.

I’ve tried playing around with module augmentation (using this technique for the first time, actually), but got a following error: Cannot augment module 'jimp' because it resolves to a non-module entity.

The project details are as follows.

  • NodeJS environment.
  • Jimp 0.2.28, installed with npm.
  • TypeScript 2.6.2.
  • tsconfig.json:
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "strict": true,
    "outDir": "dist",
    "lib": [
      "es5",
      "es2015.iterable"
    ]
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
dtrofimovcommented, Jan 29, 2018

@brendtumi, you’ve just shown how to use static methods (Jimp.read(buffer)) to read an existing image.

But I need to create an image from scratch, and there are several overloaded constructors for that in jimp.d.ts (which are not actually constructors, as they don’t compile with new), and there’s an explicit instruction to use new Jimp(...) for this case in the readme. Does it mean that the readme is outdated?

2reactions
jagoecommented, Apr 12, 2018

You’re right, that’s nothing but a quick fix. I looked into it and created a pull request (#430) that should fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting image build error when triggering dockerhub ...
I've started a new Vue project, builded by the Vue CLI. I want to use docker, and I'm having no problems building the...
Read more >
Typescript compile fails in build - works locally - CircleCI Discuss
Hi, I'm getting the following build failures - which don't appear locally: npm test door-key@1.0.6 test /home/ubuntu/door-key tsc ...
Read more >
Making good use of // @ts-expect-error in TypeScript
// @ts-expect-error is a special comment that instructs the compiler to ignore any issues it finds when processing the next line. You should...
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. Try TypeScript Now. Online or...
Read more >
Building Lambda functions with TypeScript
To transpile your TypeScript code, set up a compiler such as esbuild or Microsoft's TypeScript compiler ( tsc ) , which is bundled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found