Skip to content

Does not support export as "string literal"Β #56200

Closed
@laverdet

Description

@laverdet

πŸ”Ž Search Terms

"export as", "string literal"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about [syntax]

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20231023#code/MYewdgzgLgBAbgQwDYFcCmMC8MCMBuAKDQA8AHEAJ1gG95l0YEIYAiBMGE8qlmAXzxA

πŸ’» Code

const value = 1;
export { value as "an export" };

πŸ™ Actual behavior

Cannot find module 'an export' or its corresponding type declarations.(2307)

πŸ™‚ Expected behavior

It should compile correctly and emit a parseable .d.ts if configured in the project's settings.

See plain JavaScript example:

lib.mjs

const value = 1;
export { value as "an export" };

main.mjs

import * as lib from "./lib.mjs";
console.log(lib);

node main.mjs

[Module: null prototype] { 'an export': 1 }

Additional information about the issue

This fails the "TypeScript is a superset of JavaScript" assertion in the project's description.

Relevant syntax documentation can be found here:
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export#syntax

And in the language specification, 16.2 Modules:
https://tc39.es/ecma262/#prod-ModuleExportName

[...]
ModuleExportName:
  IdentifierName
  StringLiteral

It seems like an exotic request but has benefits for CSS modules which export classes as named exports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions