ts-morph icon indicating copy to clipboard operation
ts-morph copied to clipboard

Duplicate method declarations exists in the emitted .d.ts file of this JS file

Open likuner opened this issue 2 years ago • 5 comments

Describe the bug

Version: 14.0.0

duplicate code exists in the .d.ts declaration file generated by ts-morph from .js file.

To Reproduce

// .js
export default {
    methods: {
        handleScroll() {}
    }
};
// .d.ts
// handleScroll is duplicate
declare namespace _default {
    namespace methods {
        function handleScroll(): void;
        function handleScroll(): void;
    }
}
export default _default;

Expected behavior no duplicate code

likuner avatar May 21 '22 15:05 likuner

@likuner could you fill in this part of the issue template to show how you reproduced the problem?

import { Project } from "ts-morph";

const project = new Project();
const sourceFile = project.createSourceFile("test.js", `export default {
    methods: {
        handleScroll() {}
    }
};`);

// reproduce the problem here

dsherret avatar May 21 '22 15:05 dsherret

@likuner could you fill in this part of the issue template to show how you reproduced the problem?

import { Project } from "ts-morph";

const project = new Project();
const sourceFile = project.createSourceFile("test.js", `export default {
    methods: {
        handleScroll() {}
    }
};`);

// reproduce the problem here
// reproduce the problem here
const { Project } = require("ts-morph");

const project = new Project({
  compilerOptions: {
      declaration: true,
      emitDeclarationOnly: true,
      noEmitOnError: true,
      allowJs: true,
      outDir: 'comp_types'
  },
  skipAddingFilesFromTsConfig: true
})

const sourceFile = project.createSourceFile("test.js", `export default {
  methods: {
      handleScroll() {}
  }
};`);

project.emit();

likuner avatar May 21 '22 15:05 likuner

Thanks! I can reproduce it. Most likely it is a bug in the ts compiler.

dsherret avatar May 21 '22 15:05 dsherret

Thanks! I can reproduce it. Most likely it is a bug in the ts compiler.

OK, please let me know after the problem is solved, I need it urgently, Thanks!

likuner avatar May 21 '22 15:05 likuner

@likuner well I won't be able to fix it because I don't have time and it's a bug with the TypeScript compiler. If you need this fixed then you can look into fixing this bug I opened in TS's repo: https://github.com/microsoft/TypeScript/issues/49200

dsherret avatar May 21 '22 15:05 dsherret

I think this one is fixed now.

dsherret avatar Mar 09 '24 20:03 dsherret