Typescript ReferenceError: Namespace is not defined

Viewed 1130

I have declared a global namespace in a typings.d.ts file like this:

declare namespace NAMESPACE {
  export enum Colours {
    GREEN = 'GREEN',
    AMBER = 'AMBER',
    RED = 'RED',
  }
}

My tsconfig looks like this:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src",
    "./global.d.ts",
    "./typings.d.ts"
  ]
}

When I'm trying to access the enum I defined in my namespace

Ex.

if (scoreColour === NAMESPACE.Colours.GREEN)) {...}

I'm getting a runtime error saying: Typescript ReferenceError: Namespace is not defined.

Do you have any idea how to solve this?

Thank you

0 Answers
Related