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.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加