Skip to content

Support “Arbitrary module namespace identifier names” #40594

Closed

Description

@ExE-Boss

Search Terms

  • Arbitrary module namespace identifier names
  • Arbitrary module namespace identifiers
  • Arbitrary module identifier names
  • Arbitrary module identifiers
  • Arbitrary module identifier
  • Arbitrary export names
  • Arbitrary export identifiers
  • string export names
  • string exports

Suggestion

Implement support for tc39/ecma262#2154.

Use Cases

This is necessary for WASM module integration.

This would also allow typing @types/webidl‑conversions without needing to use export =.


For transpiled modules, this can already be supported, since it’s just creation of arbitrary properties on the CommonJS exports object, but native modules will require module: "ESNext".

Examples

See tc39/ecma262#2154

// @showEmit
// @filename: module.d.ts
export const foo: unknown;

declare const some_imports: unknown;
export { some_imports as "some imports" };

declare const another_imports: unknown;
export { another_imports as "another imports" };

declare const extra_imports: unknown;
export { extra_imports as "extra imports" };

declare const rest_exports: unknown;
export { rest_exports as "rest exports" };

// @filename: index.ts
import { "some imports" as foo } from "./module.js";

export { foo as "some exports" } from "./module.js";
export { "another imports" as "another exports" } from "./module.js";
export { "rest exports" } from "./module.js";
export { "extra imports" as extra_imports } from "./module.js";

export * as "star exports" from "./module.js";

Workbench Repro

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Related issues

Activity

  1. ExE-Boss commented on Oct 22, 2020

    @ExE-Boss
    ContributorAuthor

    Note that Babel now has support for this: babel/babel#12091

  2. added
    Domain: ES ModulesThe issue relates to import/export style module behavior
    CommittedThe team has roadmapped this issue
    and removed
    Waiting for TC39Unactionable until TC39 reaches some conclusion
    on May 9, 2021
  3. DanielRosenwasser commented on May 9, 2021

    @DanielRosenwasser
    Member

    tc39/ecma262#2154

    import { "😊" as yay } from "...";
    
    yay();
    
    export { yay as "🦈" };

    The above code should be supported.

    The minimum viable product should have tests for:

    • esnext module output
    • es2015 or similar module output just to get an error
    • --declaration emit
      • Specific declaration emit where the compiler might generate import() type syntax.
    • Quick info, and error message tests where we might generate import() type syntax
    • Completions in import {} and export {} lists
    • Go-to-definition

    It is likely that we would never try to emit our own import() type syntax.

  4. 31 remaining items

  5. Jack-Works commented on May 15, 2023

    @Jack-Works
    Contributor

    Some progress: I recently rewrite PR for this issue. I also plan to include full support (checker, transpiler, and language service).

    I'm still working on it.

  6. evanw commented on May 24, 2024

    @evanw
    Contributor

    (For those on this thread) I gave fixing this a try: #58640

  7. Jack-Works commented on May 24, 2024

    @Jack-Works
    Contributor

    (For those on this thread) I gave fixing this a try: #58640

    I'm happy to see you pick this up! My mental health does not support me finishing my PR for now but I still want to see this happen

  8. DanielRosenwasser commented on Jun 7, 2024

    @DanielRosenwasser
    Member
  9. evanw commented on Jun 8, 2024

    @evanw
    Contributor

    Thank you for accepting this PR. I'm looking forward to using this feature in VSCode!

    One potential remaining task is syntax highlighting. I have another PR ready to go that adds support for this feature to the TypeScript language syntax definition: microsoft/TypeScript-TmLanguage#1030. Would it be possible to add that or a similar change (doesn't have to be mine) so that syntax highlighting works too?

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

    Domain: ES ModulesThe issue relates to import/export style module behaviorES NextNew featurers for ECMAScript (a.k.a. ESNext)Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions