Skip to content

Commit 1693df0

Browse files
fix: broken imports in esm + typescript <5.5 (#11)
`import * as ts from "typescript"` does not work as expected in ESM until TypeScript 5.5 (see https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#easier-api-consumption-from-ecmascript-modules). This was causing projects using an ESM eslint config with TypeScript 4.7 through 5.4 to get: ``` Oops! Something went wrong! :( ESLint: 8.57.1 TypeError: Cannot read properties of undefined (reading 'Any') ``` This changes to `import ts from "typescript"` so the import works on those older TypeScript versions in ESM. - Also increase minimum TypeScript version to 4.7.4 to align with `typescript-eslint/typescript-estree`'s supported versions.
1 parent b6ff846 commit 1693df0

13 files changed

+18
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed broken imports in ESM configs using typescript versions lower than 5.5.
6+
37
## v0.2.1
48

5-
- Decrease minimum `typescript-eslint` version to ^8.1.0 (matches import-x plugin).
9+
- Decreased minimum `typescript-eslint` version to ^8.1.0 (matches import-x plugin).
610

711
## v0.2.0
812

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export default tseslint.config(gitignore(), {
6363
},
6464
],
6565

66+
'import-x/no-named-as-default-member': 'off',
67+
6668
'n/no-missing-import': 'off',
6769

6870
'eslint-plugin/require-meta-docs-description': [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"peerDependencies": {
6464
"eslint": "^8.57.0 || ^9.0.0",
6565
"rxjs": ">=7.0.0",
66-
"typescript": ">=4.2.0"
66+
"typescript": ">=4.7.4"
6767
},
6868
"devDependencies": {
6969
"@eslint/js": "^9.14.0",

src/etc/could-be-function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript';
1+
import ts from 'typescript';
22
import { couldBeType } from './could-be-type';
33

44
export function couldBeFunction(type: ts.Type): boolean {

src/etc/could-be-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as tsutils from 'ts-api-utils';
2-
import * as ts from 'typescript';
2+
import ts from 'typescript';
33

44
export function couldBeType(
55
type: ts.Type,

src/etc/get-loc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TSESTree } from '@typescript-eslint/utils';
2-
import * as ts from 'typescript';
2+
import ts from 'typescript';
33

44
export function getLoc(node: ts.Node): TSESTree.SourceLocation {
55
const sourceFile = node.getSourceFile();

src/etc/get-type-services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
22
import * as tsutils from 'ts-api-utils';
3-
import * as ts from 'typescript';
3+
import ts from 'typescript';
44
import { couldBeFunction } from './could-be-function';
55
import { couldBeType as tsutilsEtcCouldBeType } from './could-be-type';
66
import { isArrowFunctionExpression, isFunctionDeclaration } from './is';

src/rules/no-cyclic-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TSESTree as es } from '@typescript-eslint/utils';
22
import { stripIndent } from 'common-tags';
3-
import * as ts from 'typescript';
3+
import ts from 'typescript';
44
import { defaultObservable } from '../constants';
55
import { getTypeServices, isCallExpression, isIdentifier } from '../etc';
66
import { ruleCreator } from '../utils';

src/rules/no-unsafe-subject-next.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TSESTree as es } from '@typescript-eslint/utils';
22
import * as tsutils from 'ts-api-utils';
3-
import * as ts from 'typescript';
3+
import ts from 'typescript';
44
import {
55
couldBeType,
66
getTypeServices,

src/rules/throw-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TSESTree as es, ESLintUtils } from '@typescript-eslint/utils';
22
import * as tsutils from 'ts-api-utils';
3-
import * as ts from 'typescript';
3+
import ts from 'typescript';
44
import { couldBeFunction, couldBeType, getTypeServices } from '../etc';
55
import { ruleCreator } from '../utils';
66

0 commit comments

Comments
 (0)