Shamoon
Shamoon

Reputation: 43569

Typescript: Property 'DB' does not exist on type 'Global'

In my src/app.ts, I have:

import DB from '../models'

And in src/models/index.ts, I have:

export default (() => {
    if (global.DB) {
        return global.DB
    }
    ...
    // Do some other stuff
    return something

My typings/global.d.ts has:

declare namespace NodeJS {
    export interface Global {
        DB: any;
    }
}

declare var DB: any;

And finally, my tsconfig.json has:

{
    "compilerOptions": {
        "outDir": "./built",
        "allowJs": true,
        "target": "es6",
        "esModuleInterop": true,
        "sourceMap": true
    },
    "include": [
        "./src/**/*"
    ],
    "files": [
        "typings/*"
    ]
}

But I still get the error:

Error: src/models/index.ts(7,16): error TS2339: Property 'DB' does not exist on type 'Global'.

What am I doing incorrectly?

Upvotes: 7

Views: 903

Answers (1)

Jb31
Jb31

Reputation: 1391

Your tsconfig.json is probably wrong. You're using both files and include to specify globs. files however is supposed to be used for specific (relative or absolute) paths whereas include can be used with globs.

If you merged the two paths into include, like this:

{
  "compilerOptions": {
      "outDir": "./built",
      "allowJs": true,
      "target": "es6",
      "esModuleInterop": true,
      "sourceMap": true,
  },
  "include": [
      "./src/**/*",
      "./typings/*"
  ]
}

your files should compile.

Upvotes: 6

Related Questions