dnt icon indicating copy to clipboard operation
dnt copied to clipboard

does not replace '.ts' extension on `declare module` statements

Open mfulton26 opened this issue 3 years ago • 0 comments

Example.ts
export default class Example {
  get a() {
    return 42;
  }
}

Example.augmentation.ts
import Example from "./Example.ts";

declare module "./Example.ts" {
  export default interface Example {
    b: number;
  }
}

Reflect.defineProperty(Example.prototype, "b", {
  value(this: Example) {
    return this.a * 2;
  },
});

% ./path/to/build.ts
[dnt] Transforming...
[dnt] Running npm install...

added 11 packages, and audited 12 packages in 423ms

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[dnt] Building project...
[dnt] Type checking...
src/Example.augmentation.ts:3:16 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './Example.js' instead.

3 declare module "./Example.ts" {
                 ~~~~~~~~~~~~~~

error: Uncaught (in promise) Error: Had 1 diagnostics.
        throw new Error(`Had ${diagnostics.length} diagnostics.`);
              ^
    at build (https://deno.land/x/[email protected]/mod.ts:309:15)
    at async file:///path/to/build.ts:13:1

I believe that declare module "./Example.ts" { should be declare module "./Example.js" { in the emitted src.

emitted src/Example.ts
export default class Example {
  get a() {
    return 42;
  }
}

emitted src/Example.augmentation.ts
import Example from "./Example.js";

declare module "./Example.ts" {
  export default interface Example {
    b: number;
  }
}

Reflect.defineProperty(Example.prototype, "b", {
  value(this: Example) {
    return this.a * 2;
  },
});

mfulton26 avatar Sep 05 '22 16:09 mfulton26