egoist / egoist/tsup

`export {}` was removed incorrectly in the module without export

Open
#843 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

tsup version: `6.6.3`

1. Write a module without export

```
// center.ts
declare global {
interface String {
center(width: number, fillChar?: string): string;
}
}

Sring.prototype.center=function (width:number,fillChar=" ") {
let s=this
let llength=Math.floor((width-s.length)/2)
return new Array(llength).join(fillChar)+s+new Array(width-s.length-llength).join(fillChar)
}
export {} // necessary
```
2. tsup.config.js

```
import { defineConfig } from 'tsup'

export default defineConfig({
entry: [
'src/*.ts'
],
format: ['esm','cjs'],
dts: true,
splitting: true,
sourcemap: false,
clean: true,
treeshake:true,
minify: true,
```

3. build result

// center.d.ts
```
declare global {
interface String {
center(width: number, fillChar?: string): string;
}
}
```

`export {}` removed,causes `String.prototype.center` to be unrecognized。

I have to use a hacker method:

```
// center.ts
declare global {
interface String {
center(width: number, fillChar?: string): string;
}
}

Sring.prototype.center=function (width:number,fillChar=" ") {
let s=this
let llength=Math.floor((width-s.length)/2)
return new Array(llength).join(fillChar)+s+new Array(width-s.length-llength).join(fillChar)
}
export const _=0 // replace for export {}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with center.ts and tsup.config.js, then compare the generated center.d.ts with the source declaration. Check how the declaration build handles the standalone export {}. Done means the generated declaration preserves module scope so the global String augmentation is recognized without a dummy export.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.