2017-08-31 3 views
0

Schräge Fehler mit Maschinenschrift:TS2345: Argument vom Typ X ist nicht zuordenbare Parameter vom Typ Y

enter image description here

Wie das Bild zeigt, ist der Fehler:

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'.

Hier wird das ist Code, der den Fehler verursacht:

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

Jeder weiß, was hier vor sich geht?

Antwort

2

Sie senden einen Wert mit dem Typ ErrnoException, während die Funktion, die Sie aufrufen, eine Funktion erwartet, die einen Parameter vom Typ * ErrnoException ** akzeptiert und void zurückgibt.

Sie senden:

let x = new ErrnoException; 

Während die Funktion, die Sie erwartet, rufen

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

Sie Ihre Funktion ändern können, den richtigen Parameter wie folgt zu erhalten.

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