Skip to content

TypeScript Error TS1046 #8

@AlexBroadbent

Description

@AlexBroadbent

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"]
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions