-
-
Notifications
You must be signed in to change notification settings - Fork 411
Open
Labels
Description
TypeScript uses the presence of ESM to determine whether a file represents a module or a script. This is true for both TypeScript syntax and JavaScript syntax. The rule require-module-specifiers
conflicts with this, by disallowing the export {}
syntax.
These TypeScript modules define an unused function:
function fn() {}
// This makes it a module
export {}
function fn() {}
// This makes it a module.
export const variable = ''
// So this is redundant.
export {}
// Imports make it a module
import _ from 'lodash'
function fn() {}
TypeScript scripts define a global function:
function fn() {}
// Type imports don’t make it a module
import type _ from 'lodash'
function fn() {}
// Type exports don’t make it a module
export type EmptyString = ''
Setting the TypeScript option moduleDetection
to force
forces all files into modules. This does not affect declaration files.
I suggest to allow export {}
if there is no other ESM, excluding type-only imports and exports. There’s also the rule @typescript-eslint.io/no-useless-empty-export
sxzz and alex-kinokon