microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
98.27k stars 12.21k forks source link

`export type * ...` statements in `.d.ts` files do not work (5.4 regression) #58304

Closed Blckbrry-Pi closed 2 weeks ago

Blckbrry-Pi commented 2 weeks ago

πŸ”Ž Search Terms

"ts2339", "export *", ".d.ts", "regression", "5.4", "namespace", "Property does not exist"

πŸ•— Version & Regression Information

⏯ Playground Link

(Just found out about Bug Workbench)

πŸ’» Code

Bug workbench

// @filename: orig.d.ts
export const moduleMember: "example";

// @filename: reexport.d.ts
export type * from "./orig.d.ts";

// @filename: consumer.ts
import * as Definitions from "./reexport.js";
console.log(Definitions.moduleMember); // Errors here on 5.4.2

Normal filesystem

orig.d.ts:

export const moduleMember: "example";

reexport.d.ts:

export type * from "./orig.d.ts";

consumer.ts:

import * as Definitions from "./reexport.js";
console.log(Definitions.moduleMember); // Errors here on 5.4.2+

πŸ™ Actual behavior

./node_modules/typescript-v5.3.3/bin/tsc --noEmit *.ts exited without errors

./node_modules/typescript-v5.4.2/bin/tsc --noEmit *.ts emitted error 2339:

consumer.ts:2:25 - error TS2339: Property 'moduleMember' does not exist on type 'typeof import("reexport")'.

2 console.log(Definitions.moduleMember); // Errors here on 5.4.2+
                          ~~~~~~~~~~~~

πŸ™‚ Expected behavior

./node_modules/typescript-v5.3.3/bin/tsc --noEmit *.ts to exit without errors

./node_modules/typescript-v5.4.2/bin/tsc --noEmit *.ts to exit without errors

Additional information about the issue

I was unable to build versions 5.4.0 and 5.4.1 with every-ts, and AFAIK, bug workbench doesn't support versions other than the most recent patch version.

This change may have happened by 5.4.0 or 5.4.1, but I know it definitely changed between 5.3.3 and 5.4.2.

RyanCavanaugh commented 2 weeks ago

reexport says it's only exporting the types from orig, so it's correct to not re-export the values. That's the difference between export * and export type *.

Blckbrry-Pi commented 2 weeks ago

Am I correct in saying that it does break backwards compatibility with Typescript 5.3. if you were relying on `export type to behave likeexport *in a.d.ts` file?

RyanCavanaugh commented 2 weeks ago

Bug fixes can break compat, yes

Blckbrry-Pi commented 2 weeks ago

Cool. Thank you!