r/typescript • • 14h ago

Double errors: Parameter 'err' implicitly has an 'any' type | Argument of type err:any is not assignable

0 Upvotes

Title - I don't understand why this code has been getting two errors. I have tried to declare the string type, assign some values but none of these worked. Could anyone point me in the right direction?

import {promises as fs} from 'fs';

class Logger {
    //some code lines..

    private flush(): void {
        if (this.buffer.length > 0) {
            const logLines = this.buffer.join('\n') + '\n';
            const err = this.buffer.fill('error')
            /*ERROR #1 Argument of type  "(err: any) => void" is not assignable to parameter of type "(ObjectEncodingOptions & FlagAndOpenMode & { flush?: boolean | undefined; }) | BufferEncoding | null | undefined". */
            /*ERROR #2 Parameter err implicitly has an any type*/
            fs.appendFile(this.logFile, logLines, (err) => {
                if (err) {
                    console.error('Error writing log file:', err);
                }
            });
            this.buffer = [];
        }
    }
    //one more stop method ..
}