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

allowJs option with namespaces #9474

Open
tsschaffert opened this issue Jul 1, 2016 · 3 comments
Open

allowJs option with namespaces #9474

tsschaffert opened this issue Jul 1, 2016 · 3 comments
Labels
Domain: JavaScript The issue relates to JavaScript specifically Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@tsschaffert
Copy link

I am currently trying to put the compiler option "allowJs" to use. My goal is to convert an existing JavaScript application into TypeScript step by step. The application does not use (external) modules, so I'm converting the JavaScript namespaces into real TypeScript namespaces, but I'm running into "duplicate identifier" errors as outlined below. Shouldn't it be possible to combine TypeScript and JavaScript using the same namespace? Maybe I'm doing something wrong or this is not intended, but I expected this to work.

TypeScript Version: 1.8.10

Code
File 1:

namespace myapp {
    export var c1 = 5;
}

File 2:

var myapp;
(function (myapp) {
    myapp.c2 = 4;
})(myapp || (myapp = {}));

tsconfig.json

{
    "compilerOptions": {
        "allowJs": true,
        "outFile": "dist/appBundle.js"
    }
}

Expected behavior:
Bundling the compiled code of file 1 and the code of file 2 without modifications into a single JavaScript file.

Actual behavior:
The compilation is done, but the compiler throws an error: "error TS2300: Duplicate identifier 'myapp'."

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Salsa labels Jul 1, 2016
@basarat
Copy link
Contributor

basarat commented Jul 2, 2016

Duplicate identifier 'myapp'

Personal opinion: Recommend using modules please (https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html) 🌹

@tsschaffert
Copy link
Author

I agree that modules are a better solution in many cases, but as I am working on an existing application, I want to do the conversion one step at a time.
Regardless, I still think that the option "allowJs" should at least somehow work when using namespaces.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 28, 2017

@sandersn this is would be the next step after #16489. If we track the property assignment to a target that is a parameter of a an IIFE, we should redirect the declaration to be on the argument of the IIFE instead..

@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 28, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.7, TypeScript 2.8 Jan 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@mhegazy mhegazy removed this from the TypeScript 2.9 milestone May 8, 2018
@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Salsa labels Nov 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JavaScript The issue relates to JavaScript specifically Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants