TS1148 ~ How to “import” with --module: “none” and typescript 2.x

后端 未结 4 2143
一生所求
一生所求 2021-02-14 19:02

I\'m currently working on a project with some legacy javascript. The application does not include a module loader, it just puts everything as a global into the window object. To

4条回答
  •  花落未央
    2021-02-14 19:41

    You need to export rxjs to the global namespace. There are two ways to do it, depends on the shape of rxjs.

    If rxjs export only one thing, e.g. Rx.*, then you can do this:

    // custom-typings/rxjs.d.ts
    import * from 'rxjs'
    export as namespace Rx
    
    // tsconfig.json
    {
      "include": [
        "custom-typings"
      ]
    }
    

    If it export more than one thing, then you need to do global augmentation:

    // custom-typings/rxjs.d.ts
    import * as Rx from 'rxjs'
    declare global {
      type Rx = Rx
      ...
    }
    
    // same change to tsconfig.json
    

    Here are some info on global augmentation. https://www.typescriptlang.org/docs/handbook/declaration-merging.html

提交回复
热议问题