@@ -112,10 +112,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
112112 if (
113113 allowConstantExport &&
114114 init &&
115- ( init . type === "Literal" || // 1, "foo"
116- init . type === "UnaryExpression" || // -1
117- init . type === "TemplateLiteral" || // `Some ${template}`
118- init . type === "BinaryExpression" ) // 24 * 60
115+ constantExportExpressions . has ( skipTSWrapper ( init ) . type )
119116 ) {
120117 return ;
121118 }
@@ -223,11 +220,7 @@ export const onlyExportComponents: TSESLint.RuleModule<
223220 context . report ( { messageId : "exportAll" , node } ) ;
224221 } else if ( node . type === "ExportDefaultDeclaration" ) {
225222 hasExports = true ;
226- const declaration =
227- node . declaration . type === "TSAsExpression" ||
228- node . declaration . type === "TSSatisfiesExpression"
229- ? node . declaration . expression
230- : node . declaration ;
223+ const declaration = skipTSWrapper ( node . declaration ) ;
231224 if (
232225 declaration . type === "VariableDeclaration" ||
233226 declaration . type === "FunctionDeclaration" ||
@@ -301,7 +294,22 @@ export const onlyExportComponents: TSESLint.RuleModule<
301294 } ,
302295} ;
303296
297+ const skipTSWrapper = < T extends TSESTree . Node > ( node : T ) => {
298+ if ( node . type === "TSAsExpression" || node . type === "TSSatisfiesExpression" ) {
299+ return node . expression ;
300+ }
301+ return node ;
302+ } ;
303+
304304type ToString < T > = T extends `${infer V } ` ? V : never ;
305+ const constantExportExpressions = new Set <
306+ ToString < TSESTree . Expression [ "type" ] >
307+ > ( [
308+ "Literal" , // 1, "foo"
309+ "UnaryExpression" , // -1
310+ "TemplateLiteral" , // `Some ${template}`
311+ "BinaryExpression" , // 24 * 60
312+ ] ) ;
305313const notReactComponentExpression = new Set <
306314 ToString < TSESTree . Expression [ "type" ] >
307315> ( [
0 commit comments