Combine type and value imports using Typescript 4.5 type modifier syntax

Overview

type-import-codemod

Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax.

Before:

import React, { useState } from 'react';
import type { ComponentProps } from 'react';
import type { AnotherType } from './types';

After:

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

npm install type-import-codemod

Usage

This is a 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 that you need. The only argument added by this package is the transform.

For example:

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.

You might also like...

Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called

bun-livereload Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called. import liveRelo

Dec 19, 2022

Patches the AssemblyScript compiler to utilize WASI imports instead of Web APIs.

Patches the AssemblyScript compiler to utilize WASI imports instead of Web APIs.

WASI shim for AssemblyScript Patches the AssemblyScript compiler to utilize WASI imports instead of Web APIs. Note that this shim also serves a higher

Dec 23, 2022

Resolve parallel promises in key-value pairs whilst maintaining type information

async-kv Resolves promises in key-value pairs maintaining type information. Prerequisites NodeJS 12 or later Installation npm i async-kv yarn add asyn

Feb 17, 2022

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Dec 20, 2022

In this project, I built a basic website that allows users to add/remove books from a list using HTML/CSS to build the app and JavaScript to add functionalities. This project was organized using modules and ES6 syntax implemented.

Awesome books: with ES6 Description the project. Built With HTML CSS JAVASCRIPT Live Demo (if available) Live Demo Link Getting Started This is an exa

Sep 9, 2022

A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Sep 21, 2022

The aim of this project is to restructure the Awesome books app code by using ES6 syntax and organising the workspace using modules.

Awesome-Books-ES6 The aim of this project is to restructure the Awesome books app code by using ES6 syntax and organising the workspace using modules.

Aug 18, 2022

A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

go2type go2type.vercel.app (backup site) A typescript transpiler that convert golang's type to typescript's type. Help front-end developer to work fas

Sep 26, 2022

A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods

A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods. It provides an invalidation mechanism based both on exact string and regex.

Dec 15, 2022
Comments
  • Convert implicit type imports to explicit types (using ts-morph)

    Convert implicit type imports to explicit types (using ts-morph)

    This takes a lot of inspiration from https://github.com/JamieMason/ts-import-types-cli to convert implicit type imports into explicit type imports.

    I'm not sure whether I'll actually merge this in, but I wanted to show an example of how this can be done with ts-morph.

    TODO:

    • [x] Merge converted type imports into other import declarations.
    opened by IanVS 0
Owner
Ian VanSchooten
I build front-ends and raise πŸ¦†, 🐝 & two boys.
Ian VanSchooten
Type predicate functions for checking if a value is of a specific type or asserting that it is.

As-Is Description As-Is contains two modules. Is - Type predicates for checking values are of certain types. As - Asserting values are of a certain ty

Declan Fitzpatrick 8 Feb 10, 2022
Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

null 7 Jan 14, 2022
Smooth subdivision surface modifier for use with three.js BufferGeometry.

Three Subdivide This modifier uses the Loop (Charles Loop, 1987) subdivision surface algorithm to smooth modern three.js BufferGeometry. β€” Live Demo β€”

Stephens Nunnally 26 Dec 3, 2022
🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)

?? TypeScript Primitives type TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types

CodelyTV 82 Dec 7, 2022
Very tiny function that checks if an object/array/value is shaped like another, with TypeScript type refining.

@suchipi/has-shape Very tiny (~200B before minification/compression) function that checks if an object/array/value is shaped like another, with TypeSc

Lily Skye 7 Aug 13, 2022
Keep the type of storage value unchanged and change array and object directly. Supports listening to the changes and setting expires.

proxy-web-storage A more convenient way to use storage through proxy. try it on codesandbox. Install npm i proxy-web-storage Features Base Keep the ty

null 221 Dec 25, 2022
Tracer for module requires/imports to optimize coldstarts in serverless

treq treq is a library to automatically trace requires/imports in your serverless applications and gives you insights about the most expensive modules

Serkan Γ–ZAL 29 Aug 16, 2022
An imports transform unplugin.

unplugin-transform-imports An imports transform unplugin based on babel inspired by babel-plugin-transform-imports. What unplugin-transform-imports Do

ViPro (δΊ¬δΊ¬) 7 Nov 29, 2022
Sort imports by path - VS Code extension

Import sort by absolute path The sorting algorithm will group each item in the array and sort (alphabetically) its children that starts with the path

Richard Bidin 3 Feb 2, 2022