You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
need export relative external module from ambient module decl. #2516
I am trying to facilitate use of TypeScript with ES6-based modular set of github repos. I am struggling with this pattern:
typescript compiler wont allow export declaration in an ambient external module declaration that references an external module through relative external module name
the repos use systemjs and jspm to resolve aurelia-metadata. i want to use ambient module declarations to expose the types from aurelia-metadata
what i'm trying to achieve is effectively the same as copying the contents of origin.d.ts, resource-type.d.ts, and metadata.d.ts into the ambient module declaration in aurelia.d.ts.
note that ./metadata/index.js basically publishes the public interface through its exports, and that is precisely what i want to expose in the ambient module declaration
i could surrender and manually copy the info from the compiler-generated origin.d.ts, resource-type.d.ts, and metadata.d.ts into the ambient module declaration, but have been trying to find a way to just expose what is exported in index.d.ts, as that is the public api for the module in the repo.
the issue with the manual approach is that there are already 20+ libraries, they will continue to grow, and if updating the api can't be done using the compiler, i will be forever tracking the changes in the repos and updating the api manually.
i believe that the public api for each repo must be an ambient module because the actual path to the corresponding import (aurelia-metadata in this case) is resolved using systemjs loader (the module dependencies are managed using jspm)
i will perform additional validation today, but your guidance made it possible to build the .d.ts files using gulp-typescript and then incorporate the results into ambient module declarations shown here
a spike to attempt to port aurelia code into typescript
The process is to take the ES6 Aurelia source code, maintain a local copy here for comparison when porting across new code changes: aurelia repo source code
Using the source from above, the next step in the process is to create equivalent, matching typescript source code by copying .js files and renaming them .ts extension, making small edits to make the typescript compiler happy, and as an added bonus, adding typescript type annotations for the public api: aurelia repo typescript-converted source code
The (gulp-based) build process then compiles the typescript aurelia source code, creating the .d.ts files that consist of only the type definitions. In addition, the .js files in ES6 format are created also. These files can hopefully be used by babel compiler to produce ES6 modules in register format. build output
clone and build
clone this repo
run git bash shell, change to the main folder
change to aurelia-ts folder
run npm install
change to node_modules/typescript folder
run npm install
run npm install -g jake (if you haven't already)
run jake local
run jake LKG
change back to aurelia-ts folder
run gulp build
you should now see folders in the output-gulp folder. each of these folders should contain .d.ts and .js files from the build.
process steps - to add aurelia repos (or add new files):
run ./get-latest.sh
this is a git bash script to help keep the aurelia-latest up to date
clones aurelia repos into aurelia-latest-repos
copies src folder from each repo into corresponding folder in aurelia-latest
manually copy .js files from aurelia-latest into aurelia-ts (rename each to .ts)
update gulpfile.js
if it is a new repo, add the .d.ts file in output-gulp
I struggled a bit figuring out the right combination of files and configuration settings. The TypeScript 1.5 compiler is beautiful, in my opinion. The ES6 code syntax ports over very well. It would also probably be helpful to have some guidance on what .d.ts files provide with the TypeScript repo should be used in various situations. Some sort of mapping from types to .d.ts files. I had some issues figuring out where ES6 Promises might be defined.
Overall, this is right on target.
I do think some tooling would be useful - if I could say: "generate an ambient .d.ts file for metadata/index", for example, and it would round up the types an place them in a single ambient module definition (including comments). Right now it is spread out over several .d.ts files, but it does work as is.
Mike Graham (@cmichaelgraham) FWIW atom-typescript now has integrated dts-generator and all it needs is the path to your package.json. It takes care of the rest for your automatically : #2829
Both exporting and importing should just work ™️ .
Activity
mhegazy commentedon Mar 27, 2015
silly question, what is the problem with calling the module "metadata/index" instead of "./metadata/index"?
The problem is given this definition:
that it is not clear were the "./" is relative too. is it relative to the current file (.d.ts) the referencing .ts file? or something else?
cmichaelgraham commentedon Mar 27, 2015
will that work if the contents of
./metadata/index.jsare as shown above?(and it has a corresponding
.d.tsgenerated by the compiler)i was hoping it would be relative to the current file (.d.ts)
cmichaelgraham commentedon Mar 28, 2015
i could surrender and manually copy the info from the compiler-generated origin.d.ts, resource-type.d.ts, and metadata.d.ts into the ambient module declaration, but have been trying to find a way to just expose what is exported in index.d.ts, as that is the public api for the module in the repo.
the issue with the manual approach is that there are already 20+ libraries, they will continue to grow, and if updating the api can't be done using the compiler, i will be forever tracking the changes in the repos and updating the api manually.
i believe that the public api for each repo must be an ambient module because the actual path to the corresponding import (
aurelia-metadatain this case) is resolved using systemjs loader (the module dependencies are managed using jspm)basarat commentedon Mar 30, 2015
Assuming you have
origin.d.ts:You can import / reexport it as
aurelia.d.ts:Verified from usage:
In short
Tell me exactly the TS you want to write i.e. the Usage and then we can come up with a definition for it. ❤️
basarat commentedon Mar 30, 2015
Mike Graham (@cmichaelgraham) note that my files exist online for your testing https://github.com/TypeStrong/atom-typescript-examples/tree/master/externalModulesDefinition
cmichaelgraham commentedon Mar 30, 2015
i will perform additional validation today, but your guidance made it possible to build the .d.ts files using gulp-typescript and then incorporate the results into ambient module declarations shown here
i am VERY grateful for your help !!! 😄
cmichaelgraham commentedon Mar 31, 2015
For any interested parties, here is a public github repo that illustrates the working compiler results. Thanks to Basarat Ali Syed (@basarat) & Mohamed Hegazy (@mhegazy) for the guidance !!
aurelia-ts-port
The process is to take the ES6 Aurelia source code, maintain a local copy here for comparison when porting across new code changes:
aurelia repo source code
Using the source from above, the next step in the process is to create equivalent, matching typescript source code by copying
.jsfiles and renaming them.tsextension, making small edits to make the typescript compiler happy, and as an added bonus, adding typescript type annotations for the public api:aurelia repo typescript-converted source code
The (gulp-based) build process then compiles the typescript aurelia source code, creating the
.d.tsfiles that consist of only the type definitions. In addition, the.jsfiles in ES6 format are created also. These files can hopefully be used bybabel compilerto produce ES6 modules inregisterformat.build output
clone and build
git bashshell, change to the main folderaurelia-tsfoldernpm installnode_modules/typescriptfoldernpm installnpm install -g jake(if you haven't already)jake localjake LKGaurelia-tsfoldergulp buildyou should now see folders in the
output-gulpfolder. each of these folders should contain.d.tsand.jsfiles from the build.process steps - to add aurelia repos (or add new files):
run
./get-latest.shaurelia-latest-repossrcfolder from each repo into corresponding folder inaurelia-latestmanually copy
.jsfiles fromaurelia-latestintoaurelia-ts(rename each to.ts)update
gulpfile.jsif it is a new repo, add the .d.ts file in
output-gulpmhegazy commentedon Mar 31, 2015
thanks Mike Graham (@cmichaelgraham) for sharing. I would be interested to know how did the conversion process go? what are the issues you ran into?
cmichaelgraham commentedon Mar 31, 2015
I struggled a bit figuring out the right combination of files and configuration settings. The TypeScript 1.5 compiler is beautiful, in my opinion. The ES6 code syntax ports over very well. It would also probably be helpful to have some guidance on what
.d.tsfiles provide with the TypeScript repo should be used in various situations. Some sort of mapping from types to.d.tsfiles. I had some issues figuring out where ES6 Promises might be defined.Overall, this is right on target.
I do think some tooling would be useful - if I could say: "generate an ambient
.d.tsfile formetadata/index", for example, and it would round up the types an place them in a single ambient module definition (including comments). Right now it is spread out over several.d.tsfiles, but it does work as is.mhegazy commentedon Mar 31, 2015
thanks Mike Graham (@cmichaelgraham) for the feedback. i have created issue #2568 to track the single declaration file generation.
basarat commentedon Apr 20, 2015
Mike Graham (@cmichaelgraham) FWIW atom-typescript now has integrated
dts-generatorand all it needs is the path to yourpackage.json. It takes care of the rest for your automatically : #2829Both exporting and importing should just work ™️ .