I am facing an issue with a third-party library that needs to be dynamically loaded with an authentication key.
Since the API is complex, I require type definitions in my TypeScript code for better clarity.
In my .tsconfig
file, I have set "target": "esnext"
and "module": "esnext"
.
To import type definitions from typings/third.party.d.ts
, I use the following line in my TS code:
import * as third_party from './typings/third.party';
The problem arises when this ends up in the output JS file. It should not be there since it is a .d.ts
file.
I attempted including the extension like this:
import * as third_party from './typings/third.party.d.ts';
However, this results in TS error code TS2691: "An import path cannot end with a '.d.ts' extension. Consider importing './typings/third.party' instead."
Adding the reference path like this also did not work:
/// <reference path="typings/third.party.d.ts" />
This led to the file not being found at all.
While I understand bundlers can resolve this issue, I prefer not to introduce additional dependencies. I want the TS compiler to strictly enforce the definition from the .d.ts
file without including it in the exported .js
file.
How can I achieve this?