diff --git a/packages/tsc-wrapped/src/collector.ts b/packages/tsc-wrapped/src/collector.ts index 3ad18800fc..b9b5f3a45b 100644 --- a/packages/tsc-wrapped/src/collector.ts +++ b/packages/tsc-wrapped/src/collector.ts @@ -287,13 +287,14 @@ export class MetadataCollector { const isExportedIdentifier = (identifier?: ts.Identifier) => identifier && exportMap.has(identifier.text); const isExported = - (node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration | - ts.EnumDeclaration) => isExport(node) || isExportedIdentifier(node.name); + (node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.TypeAliasDeclaration | + ts.InterfaceDeclaration | ts.EnumDeclaration) => + isExport(node) || isExportedIdentifier(node.name); const exportedIdentifierName = (identifier?: ts.Identifier) => identifier && (exportMap.get(identifier.text) || identifier.text); const exportedName = (node: ts.FunctionDeclaration | ts.ClassDeclaration | ts.InterfaceDeclaration | - ts.EnumDeclaration) => exportedIdentifierName(node.name); + ts.TypeAliasDeclaration | ts.EnumDeclaration) => exportedIdentifierName(node.name); // Predeclare classes and functions @@ -390,6 +391,17 @@ export class MetadataCollector { // Otherwise don't record metadata for the class. break; + case ts.SyntaxKind.TypeAliasDeclaration: + const typeDeclaration = node; + if (typeDeclaration.name && isExported(typeDeclaration)) { + const name = exportedName(typeDeclaration); + if (name) { + if (!metadata) metadata = {}; + metadata[name] = {__symbolic: 'interface'}; + } + } + break; + case ts.SyntaxKind.InterfaceDeclaration: const interfaceDeclaration = node; if (interfaceDeclaration.name && isExported(interfaceDeclaration)) { diff --git a/packages/tsc-wrapped/test/collector_spec.ts b/packages/tsc-wrapped/test/collector_spec.ts index 7f95df423c..9663b17a6a 100644 --- a/packages/tsc-wrapped/test/collector_spec.ts +++ b/packages/tsc-wrapped/test/collector_spec.ts @@ -34,6 +34,7 @@ describe('Collector', () => { 'exported-classes.ts', 'exported-functions.ts', 'exported-enum.ts', + 'exported-type.ts', 'exported-consts.ts', 'local-symbol-ref.ts', 'local-function-ref.ts', @@ -66,6 +67,13 @@ describe('Collector', () => { expect(metadata).toBeUndefined(); }); + it('should return an interface reference for types', () => { + const sourceFile = program.getSourceFile('/exported-type.ts'); + const metadata = collector.getMetadata(sourceFile); + expect(metadata).toEqual( + {__symbolic: 'module', version: 3, metadata: {SomeType: {__symbolic: 'interface'}}}); + }); + it('should return an interface reference for interfaces', () => { const sourceFile = program.getSourceFile('app/hero.ts'); const metadata = collector.getMetadata(sourceFile); @@ -945,7 +953,7 @@ describe('Collector', () => { it('should be able to substitute a lambda', () => { const source = createSource(` const b = 1; - export const a = () => b; + export const a = () => b; `); const metadata = collector.getMetadata(source, /* strict */ false, (value, node) => { if (node.kind === ts.SyntaxKind.ArrowFunction) { @@ -965,7 +973,7 @@ describe('Collector', () => { }); const source = createSource(` const b = 1; - export const a = () => b; + export const a = () => b; `); const metadata = collector.getMetadata(source, /* strict */ false, (value, node) => { if (node.kind === ts.SyntaxKind.ArrowFunction) { @@ -1272,6 +1280,9 @@ const FILES: Directory = { } export declare function declaredFn(); `, + 'exported-type.ts': ` + export type SomeType = 'a' | 'b'; + `, 'exported-enum.ts': ` import {constValue} from './exported-consts';