Reputation: 151
I have setup an ASP.net core MVC project with TS. I want to use TS without using any module system. Just "clean" compiled TS=>JS.
The problem I am facing, is that I can't reference a declaration file (.d.ts) in a .ts file, without using "import".
If I do use "import" code completion and type checking works, but because I have configured my project not to use any "module" system, compiler complains saying: "Cannot use imports, exports or module augmentations when '--module' is 'none'
I've already tried using triple slash directives Triple-Slash Directives and using @types, typeRoots and types in tsconfig.json files but no luck.
VS2017(same with VS Code) doesn't seem to be able resolve the referenced file.
I've set up a rudimentary project which demonstrates the problem https://github.com/gtrifidis/Asp.netCoreTypescriptDemo/tree/master/TypeScriptDemo
Any help/idea would be very much appreciated.
Upvotes: 1
Views: 751
Reputation: 2534
The problem is not that TypeScript doesn't find your d.ts file, but because in your case the file index.d.ts of i18next
is written in the module fashion, and is supposed to be used only with import
. Luckily, it is very easy to fix this; all you have to do is to go to index.d.ts and remove the last line:
....
declare const i18next: i18next.i18n;
export = i18next; // <- remove this line
And then you can go ahead and remove the import
in your LocalizationTest.ts, and it will compile just fine.
Or, as noted by @AluanHaddad, instead of removing it and create your own definition, you should submit a PR that adds a new line:
....
declare const i18next: i18next.i18n;
export = i18next;
export as namespace i18next; // <- add this instead
Upvotes: 1