Skip to content

Commit 1f692ae

Browse files
committed
feat(typings): allow declaration of reference paths
Without this feature, each bundle would have to create its own typings template to include references to dependent typings. Now, the references can be declared in JS, along with other meta information about the bundle typings. Closes angular#3540
1 parent 1562bc9 commit 1f692ae

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

docs/typescript-definition-package/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,23 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
4242
'angular2/router.ts'
4343
];
4444
readTypeScriptModules.basePath = path.resolve(path.resolve(__dirname, '../../modules'));
45-
45+
4646
createTypeDefinitionFile.typeDefinitions = [
4747
{
4848
id: 'angular2/angular2',
49+
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
4950
modules: {
5051
'angular2/angular2': 'angular2/angular2',
5152
}
5253
},
5354
{
5455
id: 'angular2/router',
56+
//Right now the typings live in the same directory, but eventually will not. See #3458
57+
references: ['../angular2/angular2.d.ts'],
5558
modules: {
5659
'angular2/router': 'angular2/router'
5760
}
58-
}
61+
}
5962
];
6063
})
6164

docs/typescript-definition-package/processors/createTypeDefinitionFile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function createTypeDefinitionFile(log) {
3333
// A type definition may include a number of top level modules
3434
// And those modules could be aliased (such as 'angular2/angular2.api' -> 'angular2/angular2')
3535
moduleDocs: _.transform(def.modules, function(moduleDocs, id, alias) {
36-
moduleDocs[id] = { id: alias, doc: null };
36+
moduleDocs[id] = { id: alias, doc: null, references: def.references };
3737
})
3838
};
3939
});
@@ -63,7 +63,7 @@ module.exports = function createTypeDefinitionFile(log) {
6363
// Convert this class to an interface with no constructor
6464
exportDoc.docType = 'interface';
6565
exportDoc.constructorDoc = null;
66-
66+
6767
if (exportDoc.heritage) {
6868
// convert the heritage since interfaces use `extends` not `implements`
6969
exportDoc.heritage = exportDoc.heritage.replace('implements', 'extends');

docs/typescript-definition-package/templates/angular2/angular2.d.ts.template.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{% extends '../type-definition.template.html' %}
22
{% block staticDeclarations %}
3-
// Angular depends transitively on these libraries.
4-
// If you don't have them installed you can run
5-
// $ tsd query es6-promise rx rx-lite --action install --save
6-
///<reference path="../es6-promise/es6-promise.d.ts"/>
7-
///<reference path="../rx/rx.d.ts"/>
83

94
interface List<T> extends Array<T> {}
105
interface Map<K,V> {}

docs/typescript-definition-package/templates/type-definition.template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
// Please do not create manual edits or send pull requests
2929
// modifying this file.
3030
// ***********************************************************
31+
{% for alias, module in doc.moduleDocs %}
32+
{%- if module.references.length %}
33+
// Angular depends transitively on these libraries.
34+
// If you don't have them installed you can install them using TSD
35+
// https://github.com/DefinitelyTyped/tsd
36+
{%- endif %}
37+
{% for reference in module.references %}
38+
///<reference path="{$ reference $}"/>{% endfor %}{% endfor %}
3139
{% block staticDeclarations %}{% endblock %}
3240
{% for alias, module in doc.moduleDocs %}
3341
{$ commentBlock(module.doc, 1) $}

0 commit comments

Comments
 (0)