Skip to content

the result of "isolatedDeclaration" removes the global declare #3952

@erwinheldy

Description

@erwinheldy

version used: oxc-transform@0.16.0

For example:

// my-function.ts
function MyFunction() {
  return 'here is my function'
}

export { MyFunction }

declare global {
  interface Window {
    MyFunction: typeof MyFunction
  }
}

window.MyFunction = MyFunction
// dts-builder.js
import { readFile, writeFile } from 'node:fs/promises'
import oxc from 'oxc-transform'

const file = 'my-function.ts'
const text = await readFile(file, 'utf8')
const code = oxc.isolatedDeclaration(file, text)
await writeFile('my-function.d.ts', code.sourceText)

Result of node dts-builder.js:

declare function MyFunction(): string;
export { MyFunction };

For comparison, this is the result of npx tsc my-function.ts --declaration --emitDeclarationOnly --isolatedDeclarations:

declare function MyFunction(): string;
export { MyFunction };
declare global {
    interface Window {
        MyFunction: typeof MyFunction;
    }
}

Metadata

Metadata

Assignees

Labels

C-bugCategory - Bug

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions