Import Sort Parser for TypeScript
import-sort-parser-typescript is a specialized parser module designed for the import-sort ecosystem, specifically to handle TypeScript and TSX files. It leverages the native TypeScript compiler for syntax parsing, enabling import sorting based on the TypeScript language rules. As a component, it is typically used in conjunction with `import-sort`, `import-sort-config`, and a chosen sorting style. The package is currently at version 6.0.0, but was last published approximately 7 years ago, suggesting a maintenance or possibly abandoned status rather than active development. Its primary differentiation lies in using the TypeScript parser directly, which historically provided accurate parsing for TypeScript-specific constructs, but its age raises concerns about compatibility with recent TypeScript versions and features. Release cadence is effectively halted given its last update.
Common errors
-
SyntaxError: Unexpected token '...', '...' expected (or similar parsing errors for new TS syntax)
cause Using `import-sort-parser-typescript` (last updated 7 years ago) with a modern TypeScript codebase that utilizes recent language features not understood by the outdated parser.fixDowngrade your TypeScript version (not recommended) or, preferably, switch to a more modern import sorting tool or plugin that is actively maintained and supports your current TypeScript version. Refer to the warnings for alternatives. -
Error: Unknown parser: "import-sort-parser-typescript"
cause Incorrectly specifying the parser in your `import-sort` configuration by using the full package name instead of the designated alias.fixIn your `importSort` configuration (e.g., in `package.json` or `.importsortrc.json`), ensure the parser is specified as `"parser": "typescript"` (the alias) and not `"parser": "import-sort-parser-typescript"`.
Warnings
- breaking The package `import-sort-parser-typescript` has not been updated in approximately 7 years (last published Feb 16, 2019). This means it likely does not support newer TypeScript syntax features (e.g., decorators, new module resolutions, syntax additions in TS 4.x and 5.x) which can lead to parsing errors or incorrect sorting for modern TypeScript codebases.
- gotcha This package is a parser for the `import-sort` ecosystem, not a standalone tool. It must be used with `import-sort` (e.g., via `import-sort-cli` or an editor extension) and configured to specify the 'typescript' parser. Direct programmatic use for parsing outside of the `import-sort` runner is uncommon.
- deprecated Given its age, the `import-sort` ecosystem itself might be considered deprecated by many modern TypeScript workflows in favor of built-in editor features, Prettier plugins, or ESLint rules for import sorting.
Install
-
npm install import-sort-parser-typescript -
yarn add import-sort-parser-typescript -
pnpm add import-sort-parser-typescript
Imports
- parser
import { parser } from 'import-sort-parser-typescript';import parser from 'import-sort-parser-typescript';
- Parser Configuration
"parser": "import-sort-parser-typescript"
{ "importSort": { "parser": "typescript" } }
Quickstart
{
"name": "my-project",
"version": "1.0.0",
"description": "Example project using import-sort with TypeScript",
"main": "index.js",
"scripts": {
"sort-imports": "import-sort -l"
},
"devDependencies": {
"import-sort": "^5.0.0",
"import-sort-cli": "^6.0.0",
"import-sort-config": "^6.0.0",
"import-sort-parser-typescript": "^6.0.0",
"import-sort-style-renke": "^6.0.0",
"typescript": "^4.0.0"
},
"importSort": {
"\.ts$": {
"parser": "typescript",
"style": "renke"
},
"\.tsx?$": {
"parser": "typescript",
"style": "renke"
}
}
}
// To use this, save the above as package.json, then run:
// npm install
// npm run sort-imports