Skip to content
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

export import of types is not allowed in namespaces when using erasableSyntaxOnly #61326

Open
phryneas opened this issue Mar 1, 2025 · 3 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@phryneas
Copy link

phryneas commented Mar 1, 2025

πŸ”Ž Search Terms

export import alias type-only namespaces erasableSyntaxOnly

πŸ•— Version & Regression Information

  • I was unable to test this on prior versions because erasableSyntaxOnly was just released

⏯ Playground Link

https://www.typescriptlang.org/play/?erasableSyntaxOnly=true&ts=5.8.2#code/PTAEBcAsEsGdQO4HsBOBrWBYAUAOwIYC2AprAA74DGxEAnmaaAN46ijEAeZq4oAJsUoAbfChrh6NAGJIkbALygAjDgC+OHCFAAjAK68ocfklK4A5L2ToANKHxCoSXQHNIoaODPwJDALRJcIVpbcFkcAhJyKnFJWAB1D0gAJWJObhReFmw2NJ53QnTeABVQRR9GNQ1sLUN4IyQ0fFpwolIKalAAN3tdRiycrjzKANheADNZUuVK7Bxyuyny2AA6GSQ5yVAORdiEqBTcjOWi1dkgA

πŸ’» Code

// this works
namespace types {
  export declare type Foo  = 1
}

// but this doesn't work, although it's type-only, too
namespace typesWithReexport {
  export import T = types 
}

// ignoring the error, generally these should be both accessible
type a = types.Foo
type x = typesWithReexport.T.Foo

πŸ™ Actual behavior

export import re-exporting a namespace (or namespace member) of a type-only namespace from another type-only namespace results in This syntax is not allowed when 'erasableSyntaxOnly' is enabled.

πŸ™‚ Expected behavior

It should not error.

Additional information about the issue

@jakebailey asked me to open an issue to track this on bsky: https://bsky.app/profile/jakebailey.dev/post/3ljdc3ou7oc2w

@jakebailey
Copy link
Member

Hm, maybe I misunderstood what you were reporting. Take a look at the js output for that second namespace; it has js emit and therefore cannot be allowed.

@phryneas
Copy link
Author

phryneas commented Mar 3, 2025

@jakebailey is there a way to make this possible?
Adding a statement like export import type or something like explicit type-only namespaces that will not emit maybe?

Right now, the only way around this is to re-export every type by hand by redeclaring it, and if the original type has generics, that gets very long, like

export type X<A,B,C> = types.X<A,B,C>

as it requires repeating all generics of the original type, and essentially erases any JSDoc unless I repeat it.

It's also very prone to run "out of sync" - if I add another generic to the original type, I might miss it in a manual "re-export" declaration.

@jakebailey
Copy link
Member

In its current state, no; since this uses types, it means you need cross-file analysis to do correctly.

export import type seems like a good idea, though...

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants