0
votes

Weird error with TypeScript:

enter image description here

As the image indicates, the error is:

TS2345: Argument of type 'ErrnoException' is not assignable to parameter of type '(err: ErrnoException) => void'. Type 'ErrnoException' provides no match for the signature '(err: ErrnoException): void'.

Here is the code that causes the error:

export const bump = function(cb: ErrnoException){
  const {pkg, pkgPath} = syncSetup();
  fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), cb);
};

Anybody know what's going on here?

1

1 Answers

2
votes

You are sending a value with the type ErrnoException, while the function you are calling expects a function that takes a parameter of type *ErrnoException** and returns void.

You send:

let x = new ErrnoException;

While the function you call expects

let cb = function(e: ErrnoException) {};

You can change your function to receive the correct parameter like this.

export const bump = function(cb: (err: ErrnoException) => void){
  const {pkg, pkgPath} = syncSetup();
  fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), cb);
};