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

dotted names in export assignments #4325

Closed
vladima opened this issue Aug 15, 2015 · 6 comments
Closed

dotted names in export assignments #4325

vladima opened this issue Aug 15, 2015 · 6 comments
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@vladima
Copy link
Contributor

vladima commented Aug 15, 2015

Current description of export assignments in the spec states:

Export assignments exist for backward compatibility with earlier versions of TypeScript. An export assignment designates a module member as the entity to be exported in place of the module itself.

  ExportAssignment:
   export=IdentifierReference;

A module containing an export assignment can be imported using an import require declaration (11.3.3), and the local alias introduced by the import require declaration then takes on all meanings of the identifier named in the export assignment.

However current implementation also permits dotted names - in this case only value meaning is exported. This change seems to be quite recent, example below compiles with no errors in current master and issues a syntax error ';' expected."in v1.4.

declare module foo.bar {
    export type X = number;
    export var X: { A: number };
}

declare module "test" {
    export = foo.bar;
}

This issue can have several interpretations:

  • this is only spec bug - current behavior for dotted names should be documented
  • this is both spec and implementation issue - we export all meanings also for dotted names and spec should be adjusted to reflect this
  • this is implementation bug - we should prohibit usage of dotted names in export assignments.
@vladima
Copy link
Contributor Author

vladima commented Aug 15, 2015

adding @alexeagle since he reported this issue originally

@mhegazy mhegazy added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Aug 17, 2015
@alexeagle
Copy link
Contributor

+cc @mprobst

@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2015

We have another report of this issue for export default in #4395

@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2015

As a work around, you can use aliases:

declare module foo.bar {
    export type X = number;
    export var X: { A: number };
}

declare module "test" {
    import _alias = foo.bar;
    export = _alias;
}

@mhegazy mhegazy self-assigned this Sep 18, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Sep 18, 2015
@mhegazy mhegazy modified the milestones: TypeScript 1.7, TypeScript 1.8 Oct 9, 2015
@mhegazy mhegazy modified the milestones: TypeScript 1.8, TypeScript 2.0 Dec 8, 2015
@mhegazy mhegazy modified the milestone: TypeScript 2.0 Feb 20, 2016
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus and removed Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Feb 22, 2016
@mhegazy mhegazy removed their assignment Feb 22, 2016
@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Apr 20, 2016
@RyanCavanaugh
Copy link
Member

Do we need to do anything here other than update the spec?

@mhegazy
Copy link
Contributor

mhegazy commented Apr 20, 2016

yes. we need to implement it. currently we only support exporting all meanings of export = <identifier> and only the value side of export = <dotted name>.

The main issue we can not trust that a dotted name resolves to a single symbol that we can resolve to. so what we need is create a new alias symbol, and then resolve the module to that. i.e. emulate:

import _export = a.b.c;
export = _export;

@mhegazy mhegazy added this to the TypeScript 2.1 milestone Jun 10, 2016
@mhegazy mhegazy assigned ghost Jun 10, 2016
@ghost ghost closed this as completed in #10013 Aug 11, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.0.1, TypeScript 2.1 Aug 17, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 17, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants