Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 425
Shamoon Avatar asked Sep 22 '19 11:09

Shamoon


1 Answers

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.

like image 119
Jb31 Avatar answered Nov 10 '22 13:11

Jb31