Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports are lost when importing esm-like moduleswithout default export using commonjs import or esm import default #230

Closed
sunafterrainwm opened this issue Nov 24, 2022 · 1 comment · Fixed by #245
Assignees
Labels
Milestone

Comments

@sunafterrainwm
Copy link

sunafterrainwm commented Nov 24, 2022

Bug report
Imports are lost when importing esm-like export * from ... modules without default export using commonjs import import a = require( "mod" ) or esm import default import a from "mod"

Input code

example.ts

import repl1 = require( "node:repl" );
import repl2 from "node:repl";
import * as repl3 from "node:repl";

export interface MyReplOptions1 extends repl1.ReplOptions {}
export interface MyReplOptions2 extends repl2.ReplOptions {}
export interface MyReplOptions3 extends repl3.ReplOptions {}

tsconfig.json

{
	"compilerOptions": {
		"target": "es2016",
		"module": "commonjs",
		"moduleResolution": "node",
		"declaration": true,
		"allowSyntheticDefaultImports": true,
		"esModuleInterop": true
	}
}

node_modules/@types/node/repl.d.ts (copy from @types/node@18.11.9)

declare module 'repl' {
    // some unimportant code(s) have been removed
    interface ReplOptions {
        // some unimportant code(s) have been removed
    }
    // some unimportant code(s) have been removed
}
declare module 'node:repl' {
    export * from 'repl';
}

command

dts-bundle-generator --project tsconfig.json example.ts

Expected output

example.d.ts

// Generated by dts-bundle-generator v7.1.0

import repl1 = require( "node:repl" );
import repl2 from "node:repl";
import * as repl3 from 'node:repl';

export interface MyReplOptions1 extends repl1.ReplOptions {
}
export interface MyReplOptions2 extends repl2.ReplOptions {
}
export interface MyReplOptions3 extends repl3.ReplOptions {
}

export {};

Or, If this import method fails to generate a definition file normally, the program should have an explicit warning.

Actual output

example.d.ts

// Generated by dts-bundle-generator v7.1.0

import * as repl3 from 'node:repl';

export interface MyReplOptions1 extends repl1.ReplOptions {
}
export interface MyReplOptions2 extends repl2.ReplOptions {
}
export interface MyReplOptions3 extends repl3.ReplOptions {
}

export {};

command output

Compiling input files...
Processing example.ts
Writing example.ts -> example.d.ts
Checking generated files...
example.d.ts(5,41): error TS2833: Cannot find namespace 'repl1'. Did you mean 'repl3'?
example.d.ts(7,41): error TS2833: Cannot find namespace 'repl2'. Did you mean 'repl3'?

Error: Compiled with errors

Additional context
Add any other context about the problem here (CLI options, etc)
typescript 4.9.3 / dts-bundle-generator v7.1.0

@timocov
Copy link
Owner

timocov commented Mar 30, 2023

Released in v8.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants