-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Re-exporting CJS module with export =
from ESM via export *
causes type error
#51923
Comments
So, IIRC, we didn't allow this because what meanings, exactly, the declare module "interface" {
interface Foo {
x: number;
y: number;
}
export = Foo;
} or, more interestingly, declare module "variable" {
var Foo: {
a: number;
b: number;
}
export = Foo;
} Even in modern // @filename: a.ts
export = { a: 0 }
// @filename: b.ts
export * from './a'; It's maybe unclear that So while we could remove the error, I think it's probably still pointing out likely issues when people cross module system boundaries. |
There's lots of cases where a cjs package described with |
add workaround for exporting types from fastify's cjs module "export =" microsoft/TypeScript#51923
* fix: explicit type export add workaround for exporting types from fastify's cjs module "export =" microsoft/TypeScript#51923 * security: update mocha to v10.2.0 upgrade mocha to fix npm audit with a high result
Bug Report
TypeScript raises diagnostics when re-exporting a cjs package whose type declaration is defined with
export =
viaexport *
in an ES module.🔎 Search Terms
🕗 Version & Regression Information
5.0.0-dev.20221216
⏯ Playground Link
N/A - multiple files
💻 Code
mkdir scratch && cd scratch
npm init -y
npm i react @types/react typescript@next
🙁 Actual behavior
Try type checking & emitting:
It will emit, so try running it and see that it works:
🙂 Expected behavior
Should type check fine because this works at runtime and
export =
matches the runtime code which has a singlemodule .exports = ...
assignment.The text was updated successfully, but these errors were encountered: