Skip to content

Name overload term/type module re-export as namespaceΒ #51109

Open

Description

Suggestion

πŸ” Search Terms

I wasn't sure what terms to be searching for this.

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Currently this is possible:

export type A = 1
export namespace A {
  export const foo = 2
}
import { A } from './a.js'

console.log(A.foo)
const A: A = 2 // type errror

However this is not possible:

export type A = 1
export * as A from './something/else/somewhere/else.js'

πŸ“ƒ Motivating Example

CleanShot 2022-10-08 at 08 39 55@2x

I want to be able to reuse a name for a type and namespace for more streamlined downstream usage.

πŸ’» Use Cases

All the same use-cases there already are today for namespace name overloading between terms/types.

Activity

  1. MartinJohns commented on Oct 8, 2022

    @MartinJohns
    Contributor

    I believe this to be a duplicate of #48764 (comment).

  2. jasonkuhrt commented on Oct 8, 2022

    @jasonkuhrt
    Author

    Thanks Martin Johns (@MartinJohns). That issue was about the type import while mine is a suggestion that it should work like namespaces.

    That issue was/is closed with the counter-example of importing a class.

    What I'm saying here wouldn't be closed because of that counter example.

    I'm merely saying it works with namespace and ought to work with native ESM modules now that we have them.

  3. cruhl commented on Oct 25, 2022

    @cruhl

    I have been trying to get something like this working for literal years now.

    It would dramatically help write better functional/Rust-module-style code.

  4. cruhl commented on Oct 25, 2022

    @cruhl

    Jason Kuhrt (@jasonkuhrt) check out this related issue/discussion:

    #39865

  5. cruhl commented on Oct 25, 2022

    @cruhl

    Another relevant discussion...

    #48764 (comment)

  6. cruhl commented on Oct 25, 2022

    @cruhl

    Good overview of the resulting friction this would alleviate here:
    #48764 (comment)

  7. cruhl commented on Oct 25, 2022

    @cruhl

    Here's a good example of the awkwardness this causes for users of Giulio Canti (@gcanti)'s fp-ts...
    gcanti/fp-ts#1633

  8. cruhl commented on Oct 25, 2022

    @cruhl

    Here is my dream syntax...
    import * as User, type { User } from "./User";

  9. cruhl commented on Oct 25, 2022

    @cruhl
  10. cruhl commented on Oct 25, 2022

    @cruhl

    This problem won't be going away anytime soon, so I would expect it to continually pop up so long as issues keep getting closed...

    CleanShot 2022-10-25 at 13 52 01

  11. cruhl commented on Oct 25, 2022

    @cruhl

    Oddly, this halfway works, but fails to see export * as Point from "./Point"; correctly...

    'Point' only refers to a type, but is being used as a value here.ts(2693)

    CleanShot 2022-10-25 at 14 00 45
    CleanShot 2022-10-25 at 14 01 30

  12. cruhl commented on Oct 25, 2022

    @cruhl

    So this actually works...
    CleanShot 2022-10-25 at 14 12 54
    CleanShot 2022-10-25 at 14 13 04
    CleanShot 2022-10-25 at 14 13 26

  13. cruhl commented on Oct 27, 2022

    @cruhl

    So this actually works...

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions