1

Created a method to delete the file in directory.

const delete: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void = (dirName, fileName, callback) => {
  fs.unlink(baseDataDir + dirName + "/" + fileName + ".json", (error) => {
    if (!error) {
      callback(false);
    } else {
      callback(error);
    }
  });
};

const fsHandler: IFSHandler = {
  create,
  read,
  update,
  delete
};

module.exports = fsHandler;

Interface defined for fsHandler:

export interface IFSHandler {
  create: (dirName: string, fileName: string, data: any, callback: (error: string | boolean) => void) => void;
  read: (dirName: string, fileName: string, callback: (error: string | boolean, data: any) => void) => void;
  update: (dirName: string, fileName: string, data: any, callback: (error: string | boolean, fileDesc: any) => void) => void;
  delete: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void;
}

Typescript Errors:

yarn run v1.13.0
$ tsc && node dist/index.js
src/services/fsHandler.ts:69:7 - error TS1134: Variable declaration expected.

69 const delete: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void = (dirName, fileName, callback) => {
         ~~~~~~

src/services/fsHandler.ts:69:13 - error TS1109: Expression expected.

69 const delete: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void = (dirName, fileName, callback) => {
               ~

src/services/fsHandler.ts:69:104 - error TS1109: Expression expected.

69 const delete: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void = (dirName, fileName, callback) => {
                                                                                                          ~

src/services/fsHandler.ts:84:1 - error TS1005: ':' expected.

84 };
   ~


Found 4 errors.

error Command failed with exit code 2.

1 Answer 1

4

delete is a reserved keyword you cannot use delete for variable name. Change it to something else like remove and it will work.

const remove: (dirName: string, fileName: string, callback: (error: string | boolean) => void) => void = (dirName, fileName, callback) => {
  fs.unlink(baseDataDir + dirName + "/" + fileName + ".json", (error) => {
    if (!error) {
      callback(false);
    } else {
      callback(error);
    }
  });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.