Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IanVS/type-import-codemod
Combine type and value imports using Typescript 4.5 type modifier syntax
https://github.com/IanVS/type-import-codemod
Last synced: 3 months ago
JSON representation
Combine type and value imports using Typescript 4.5 type modifier syntax
- Host: GitHub
- URL: https://github.com/IanVS/type-import-codemod
- Owner: IanVS
- License: mit
- Created: 2022-03-15T22:13:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-07T19:01:46.000Z (over 2 years ago)
- Last Synced: 2024-05-01T12:46:01.409Z (10 months ago)
- Language: TypeScript
- Size: 103 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codemods - type-import-codemod - Combine type and value imports using Typescript 4.5 type modifier syntax. (Typescript)
README
# type-import-codemod
Combines your type and value imports together into a single statement, using [Typescript 4.5's type modifier syntax](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#type-on-import-names).
Before:
```ts
import React, { useState } from 'react';
import type { ComponentProps } from 'react';
import type { AnotherType } from './types';
```After:
```ts
import React, { useState, type ComponentProps } from 'react';
import type { AnotherType } from './types';
```Note, the type import from react was placed at the end of the value imports, and the import from './types' was not changed. Type imports will not be modified, unless they can be combined into another import statement, as shown for the react imports.
## Installation
```bash
npm install type-import-codemod
```## Usage
This is a [jscodeshift](https://www.npmjs.com/package/jscodeshift) transform, with a simple wrapper script to call jscodeshift for you. You should specify the file/directories to run the codemod on, as well as any other [jscodeshift arguments](https://github.com/facebook/jscodeshift#usage-cli) that you need. The only argument added by this package is the transform.
For example:
```shell
npx type-import-codemod src --extensions=tsx --parser=tsx
```This will run the transform on all files ending in `.tsx` in the `./src` directory, using the correct parser.
**Note**: Be sure to commit changes to your files before running this tool, as it can potentially cause a lot of changes. If in doubt, use the `--dry` and `--print` flags to see what effect the transform will have, before it makes changes to your files.