diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index f648df4b4f8..97dc43a5ee2 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -172,12 +172,15 @@ export class Converter { range: [exportKeyword.getStart(this.ast), result.range[1]], }); } else { + const isType = + result.type === AST_NODE_TYPES.TSInterfaceDeclaration || + result.type === AST_NODE_TYPES.TSTypeAliasDeclaration; return this.createNode(node, { type: AST_NODE_TYPES.ExportNamedDeclaration, declaration: result, specifiers: [], source: null, - exportKind: 'value', + exportKind: isType ? 'type' : 'value', range: [exportKeyword.getStart(this.ast), result.range[1]], }); } diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 5c55e89e605..6a2426b147f 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -252,20 +252,34 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { * TS 3.8 import/export type * babel coming soon https://github.com/babel/babel/pull/11171 */ - ExportNamedDeclaration(node) { + ExportNamedDeclaration(node: any) { /** * TS 3.8: export type */ if (!node.exportKind) { - node.exportKind = 'value'; + if ( + node.declaration?.type === AST_NODE_TYPES.TSTypeAliasDeclaration || + node.declaration?.type === AST_NODE_TYPES.TSInterfaceDeclaration + ) { + node.exportKind = 'type'; + } else { + node.exportKind = 'value'; + } } }, - ExportAllDeclaration(node) { + ExportAllDeclaration(node: any) { /** * TS 3.8: export type */ if (!node.exportKind) { - node.exportKind = 'value'; + if ( + node.declaration?.type === AST_NODE_TYPES.TSTypeAliasDeclaration || + node.declaration?.type === AST_NODE_TYPES.TSInterfaceDeclaration + ) { + node.exportKind = 'type'; + } else { + node.exportKind = 'value'; + } } }, ImportDeclaration(node) { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index bdbf0fc7693..04f175a15d8 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -4476,7 +4476,7 @@ Object { ], "type": "TSInterfaceDeclaration", }, - "exportKind": "value", + "exportKind": "type", "loc": Object { "end": Object { "column": 1, @@ -98017,7 +98017,7 @@ Object { ], }, }, - "exportKind": "value", + "exportKind": "type", "loc": Object { "end": Object { "column": 40, @@ -98346,7 +98346,7 @@ Object { "type": "TSFunctionType", }, }, - "exportKind": "value", + "exportKind": "type", "loc": Object { "end": Object { "column": 47, @@ -98731,7 +98731,7 @@ Object { "type": "TSTypeLiteral", }, }, - "exportKind": "value", + "exportKind": "type", "loc": Object { "end": Object { "column": 2, @@ -151165,7 +151165,7 @@ Object { ], "type": "TSInterfaceDeclaration", }, - "exportKind": "value", + "exportKind": "type", "loc": Object { "end": Object { "column": 9,