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

后端 未结 4 2132
一生所求
一生所求 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

    I've got a little project (embedded in an existing SharePoint solution) where I am trying to setup the absolute minimal Typescript tooling. I've added the Typescript MSBuild Nuget package, which includes the compiler and allows compile on save (VS2015R3). I had to throw in a tsconfig.json because I wanted to enable decorators and add some other tweaks. I don't want a module loader though so I have module: none.

    Using a lib folder where I manually copied and renamed module.d.ts files, and adding triple-slash reference directives in my ts file worked at first, but as soon as I added another file I got warnings about redeclaring globals (because both files have the same references). My solution was to just add another typescript file, move all my triple-slash references there, and replace them in my real Typescript files with one reference to my "base" file. I also threw some other shared code in there and everything works. (I could add the code if that helps, but it is fairly specific to what I'm doing)

    It seems like you could setup your tsconfig to include this base file in all compiled outputs, but for my use case I just added the base file as another script in my HTML.

    I've looked around, and there doesn't seem to be any help regarding this kind of setup. Seems a shame since this is a great way to introduce a team to Typescript without all the tool chain baggage.

提交回复
热议问题