fazlulkarimweb/string-sanitizer

TypeScript Error TS1046

Opened this issue · 2 comments

Upon building, I get the following error:

yarn run v1.22.11
$ tsc
node_modules/string-sanitizer/index.d.ts:13:1 - error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.

13 const sanitize: ISanitize;
   ~~~~~


Found 1 error.

error Command failed with exit code 2.

From looking around, it looks like you add a module to the existing d.ts file so it becomes:

declare module 'string-sanitizer' {
  type TSanitizer = (s: string) => string

  interface ISanitize extends TSanitizer {
    keepUnicode: TSanitizer
    keepSpace: TSanitizer
    addFullstop: TSanitizer
    addUnderscore: TSanitizer
    addDash: TSanitizer
    removeNumber: TSanitizer
    keepNumber: TSanitizer
  }

  const sanitize: ISanitize
  const addFullstop: TSanitizer
  const addUnderscore: TSanitizer
  const addDash: TSanitizer
  const removeSpace: TSanitizer

  export { sanitize, addFullstop, addUnderscore, addDash, removeSpace }
}

As a workaround, you can add the above file to a directory such as types/string-sanitizer.d.ts then point to it in your tsconfig.json with:

{
  "compilerOptions": {
    "paths": {
      "string-sanitizer": ["types/string-sanitizer.d.ts"]
    }
  }
}

@AlexBroadbent You could open a pull request with that change, that would be great

Done, just waiting on @fazlulkarimweb to review #15