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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With