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

dts file doesn't match export = #338

Closed
privatenumber opened this issue Jun 24, 2021 · 3 comments
Closed

dts file doesn't match export = #338

privatenumber opened this issue Jun 24, 2021 · 3 comments

Comments

@privatenumber
Copy link
Contributor

When using export = with --dts --no-splitting, the declaration file uses export default instead of export = .

Input

src/index.ts

function hello(name: string) {
	console.log(`Hello ${name}`);
}

export = hello;

package.json

{
  "scripts": {
    "build": "tsup src/index.ts --dts --no-splitting"
  },
  "devDependencies": {
    "tsup": "^4.11.2",
    "typescript": "^4.3.4"
  }
}

tsconfig.json

{
	"compilerOptions": {
		"isolatedModules": true,
		"esModuleInterop": true,
		"declaration": true,
		"outDir": "dist",
		"module": "commonjs"
	},
	"include": [
		"src"
	]
}

Output

dist/index.js

// src/index.ts
function hello(name) {
  console.log(`Hello ${name}`);
}
module.exports = hello;

dist/index.d.ts

declare function hello(name: string): void;

export default hello; // should be export = hello
@privatenumber
Copy link
Contributor Author

I think I spoke to soon actually.

I thought it had to be export = because that's what tsc outputs, but seems Typescript handles this fine when importing it.

@privatenumber
Copy link
Contributor Author

I'm noticing intellisense doesn't actually work when importing the module via CJS require.

But since it's TypeScript, I guess it's reasonable to expect all imports would be ESM import.

Would still be nice to have it be export = for correctness and Intellisense but no longer a blocker for me. Feel free to re-open.

@egoist
Copy link
Owner

egoist commented Jun 24, 2021

rollup-plugin-dts doesn't support export = pattern If I recall correctly.

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

No branches or pull requests

2 participants