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
Allow type-only named re-exports along with assigned export in the same file #38866
Comments
@RyanCavanaugh any updates on this one? Looks like it got lost in the backlog |
person.ts: import personValue from "./person-value";
namespace personValue {
export type PersonType = import("./person-type").default;
}
export = personValue; usage.ts: import person = require("./person");
person.name; // string;
const p: person.PersonType = { name: "Andrew" }; Or even, if you prefer person.ts: import person from "./person-value";
type person = import("./person-type").default;
export = person; usage.ts: import Person = require("./person");
Person.name; // string;
const p: Person = { name: "Andrew" }; I feel like these achieve the kind of bundling you want without mixing the semantics of two different module systems, which are already quite confusing without allowing additional blending. |
Hey, Andrew 👋 Thanks for the response! This isn’t exactly the kind of bundling that I’m trying to achieve, unfortunately; it’s too “tight” in both examples. I’d like to keep value and type as two separate entities, so that users have more control over what they use. This preserves a notion of single required “primary” entity (export) and multiple optional “secondary” entities per module. There’s also an issue with the second example: it’s casing suggests the value of Basically, I want this: // TypeScript
import value, { Type } from "value"; // JavaScript (CommonJS)
const value = require("value"); … so that |
The problem is that I only dropped by here because I was searching for outstanding feedback on type-only imports, so this turned up in my search but wasn’t relevant to what I’m working on. But when I read it, it looked clear to me that a solution already exists, and maybe you could benefit from it. |
Thanks for dropping by 🙂 Feel free to ignore this comment if you don’t want to continue conversation. Your input was nevertheless very valuable, I’ll definitely consider the existing solution. Okay, let’s start with a blank slate and work from there. There is a “primary” entity, At this point, I could have just use The preferred syntaxes are indeed incompatible out of the box, but with a bit of clever (I am just avoiding to say “ugly”) merging this can be achieved. The problem arises when another entity appears,— Because of the choice of importing construct for CommonJS files (I don’t want some weird stuff like But using Hence, the suggestion: allow type-only entities to be exported together with assignment export in one file. |
Search Terms
allow export types assigned =
Suggestion
The suggestion is to allow compilation of files that do both
export =
andexport type {}
.Use Cases
For modules that target both TypeScript and CommonJS usage it would allow consolidating all exports for both module systems in one file (albeit with the requirement of
esModuleInterop
beingtrue
).Currently, in order to do that I would have to utilize @ts-ignore (see parzh/xrange#69 for details).
Examples
/person.ts:
/person-type.ts:
/person-value.ts:
Usage:
/usage.ts:
/usage.js:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: