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

Shamoon

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?

Jb31

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How to prevent "Property '...' does not exist on type 'Global'" with jsdom and typescript?

分類Dev

property then does not exist on type void , A typescript error

分類Dev

Typescript property does not exist on union type

分類Dev

useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'

分類Dev

Typescript - property scan does not exist on type Subject...?

分類Dev

React & Typescript: Property 'id' does not exist on type 'number'

分類Dev

'Property does not exist on type 'never'

分類Dev

Property 'xxx' does not exist on type '{}'

分類Dev

TypeScript '...' does not exist on type 'typeof ...'

分類Dev

Typescript+React+Redux+reactrouter:"property does not exist on type IntrinsicAttributes & IntrinsicClassAttributes" passing props from parent to child

分類Dev

uisng multer with typescript: Property 'file' does not exist on type 'Request'.ts(2339)

分類Dev

TypeScript "Property does not exist on type" error when setting up a "Profile Details" page in Angular

分類Dev

Property 'values' does not exist on type 'ObjectConstructor'

分類Dev

Property 'values' does not exist on type 'ObjectConstructor'

分類Dev

TSLint: Property 'params' does not exist on type 'NavigationState'

分類Dev

Property 'subscribe' does not exist on type 'Subscription

分類Dev

Property 'entries' does not exist on type ObjectConstructor

分類Dev

Property 'innerText' does not exist on type 'Element'

分類Dev

Property 'VAR_PLURAL' does not exist on type

分類Dev

Property 'detailed' does not exist on type 'Console'

分類Dev

Property 'store' does not exist on type 'Readonly<AppInitialProps

分類Dev

Generic property 'enabled' does not exist on type 'Node'?

分類Dev

typescript does not exist on type 'typeof object

分類Dev

How to define a property to avoid: Property 'X' does not exist on type 'Y'

分類Dev

Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

分類Dev

how to fix property does not exist on type 'Object' in ionic 3?

分類Dev

Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable'

分類Dev

Angular 5 : Property 'then' does not exist on type 'Observable<any>'

分類Dev

Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

Related 関連記事

  1. 1

    How to prevent "Property '...' does not exist on type 'Global'" with jsdom and typescript?

  2. 2

    property then does not exist on type void , A typescript error

  3. 3

    Typescript property does not exist on union type

  4. 4

    useRef Typescript error: Property 'current' does not exist on type 'HTMLElement'

  5. 5

    Typescript - property scan does not exist on type Subject...?

  6. 6

    React & Typescript: Property 'id' does not exist on type 'number'

  7. 7

    'Property does not exist on type 'never'

  8. 8

    Property 'xxx' does not exist on type '{}'

  9. 9

    TypeScript '...' does not exist on type 'typeof ...'

  10. 10

    Typescript+React+Redux+reactrouter:"property does not exist on type IntrinsicAttributes & IntrinsicClassAttributes" passing props from parent to child

  11. 11

    uisng multer with typescript: Property 'file' does not exist on type 'Request'.ts(2339)

  12. 12

    TypeScript "Property does not exist on type" error when setting up a "Profile Details" page in Angular

  13. 13

    Property 'values' does not exist on type 'ObjectConstructor'

  14. 14

    Property 'values' does not exist on type 'ObjectConstructor'

  15. 15

    TSLint: Property 'params' does not exist on type 'NavigationState'

  16. 16

    Property 'subscribe' does not exist on type 'Subscription

  17. 17

    Property 'entries' does not exist on type ObjectConstructor

  18. 18

    Property 'innerText' does not exist on type 'Element'

  19. 19

    Property 'VAR_PLURAL' does not exist on type

  20. 20

    Property 'detailed' does not exist on type 'Console'

  21. 21

    Property 'store' does not exist on type 'Readonly<AppInitialProps

  22. 22

    Generic property 'enabled' does not exist on type 'Node'?

  23. 23

    typescript does not exist on type 'typeof object

  24. 24

    How to define a property to avoid: Property 'X' does not exist on type 'Y'

  25. 25

    Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

  26. 26

    how to fix property does not exist on type 'Object' in ionic 3?

  27. 27

    Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable'

  28. 28

    Angular 5 : Property 'then' does not exist on type 'Observable<any>'

  29. 29

    Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

ホットタグ

アーカイブ