Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 90dec7d

Browse files
committed
properly export interface functions
Summary: A TypeScript interface becomes a Closure function. The previous code attempted to export that function when the interface was exported, but due to microsoft/TypeScript#10122 it actually wasn't exporting. You can see this in the new test goldens, where export.js now includes "Bar" as an export. (Bar is a TypeScript interface but at the Closure level it is a value and must be in the module exports.) This also lets us remove a crazy forward declare hack that actually wasn't necessary -- it was just working around that the export wasn't working. This matches the exporting behavior in d090fe4. Reviewers: rkirov Reviewed By: rkirov Subscribers: typescript-eng Differential Revision: https://reviews.angular.io/D213
1 parent b2407a6 commit 90dec7d

File tree

6 files changed

+6
-12
lines changed

6 files changed

+6
-12
lines changed

src/tsickle.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ class Annotator extends ClosureRewriter {
582582
if (sym.flags & ts.SymbolFlags.Value) return;
583583

584584
this.emit(`\n/** @record */\n`);
585+
if (iface.flags & ts.NodeFlags.Export) this.emit('export ');
585586
let name = getIdentifierText(iface.name);
586587
this.emit(`function ${name}() {}\n`);
587588
if (iface.typeParameters) {
@@ -595,10 +596,6 @@ class Annotator extends ClosureRewriter {
595596
for (let elem of iface.members) {
596597
this.visitProperty(memberNamespace, elem);
597598
}
598-
599-
if (iface.flags & ts.NodeFlags.Export) {
600-
this.emit(`export {${name}};\n`);
601-
}
602599
}
603600

604601
// emitTypeAnnotationsHelper produces a

test_files/export/export.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
goog.module('test_files.export.export');var module = module || {id: 'test_files/export/export.js'};
22
var export_helper_1 = goog.require('test_files.export.export_helper');
33
exports.export2 = export_helper_1.export2;
4+
exports.Bar = export_helper_1.Bar;
45
exports.export5 = export_helper_1.export5;
56
exports.export4 = export_helper_1.export4;
67
// These conflict with an export discovered via the above exports,

test_files/export/export_helper.tsickle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ export {export4} from './export_helper_2';
44
export let /** @type {number} */ export1 = 3;
55
export let /** @type {number} */ export2 = 3;
66
/** @record */
7-
function Bar() {}
7+
export function Bar() {}
88
/** @type {number} */
99
Bar.prototype.barField;
10-
export {Bar};
1110

1211

1312
export interface Bar { barField: number; }
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export class Class {}
22
/** @record */
3-
function Interface() {}
3+
export function Interface() {}
44
/** @type {number} */
55
Interface.prototype.x;
6-
export {Interface};
76

87
export interface Interface { x: number }

test_files/jsdoc_types/module2.tsickle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
export class ClassOne {}
22
export class ClassTwo {}
33
/** @record */
4-
function Interface() {}
4+
export function Interface() {}
55
/** @type {number} */
66
Interface.prototype.x;
7-
export {Interface};
87

98
export interface Interface { x: number }
109
export class ClassWithParams<T> {}

test_files/jsdoc_types/nevertyped.tsickle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22
/** @record */
3-
function NeverTyped() {}
3+
export function NeverTyped() {}
44
/** @type {number} */
55
NeverTyped.prototype.foo;
6-
export {NeverTyped};
76
/* This filename is specially marked in the tsickle test
87
* suite runner so that its types are always {?}.*/
98

0 commit comments

Comments
 (0)