Feature: allow creation of new typescript 4.5 type import
See original GitHub issueThere appears to be no importKind
option that we can provide to ImportSpecifierBuilder
(j.importSpecifier()
) in order to create the new style of type import from Typescript 4.5 (https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#type-on-import-names).
I’m trying to write a codemod that changes from the old style of type imports:
import type {MyType} from './types';
to the newer style:
import {type MyType} from './types';
And this doesn’t seem possible so far. Or, am I missing it (this is my first codemod).
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 4.5
TypeScript 4.5 supports an ECMAScript proposal for import assertions. This is a syntax used by runtimes to make sure that an import has...
Read more >Announcing TypeScript 4.5 - Microsoft Developer Blogs
TypeScript 4.5 introduces a new utility type called the Awaited type. This type is meant to model operations like await in async functions, ......
Read more >What's new in TypeScript 4.5 - LogRocket Blog
In this article, we would look at the new additions to the feature-packed TypeScript 4.5. Let's get started in the next section.
Read more >Everything New in TypeScript 4.5 - JavaScript in Plain English
This feature works with normal import and dynamic import, this feature enables users to pass additional information inline. Also, this feature ...
Read more >What's New in TypeScript 4.5? - Better Programming
This is my favorite feature of this release. Starting from the version 3.8 you can explicitly use type imports by appending type to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d suggest looking at ast-types first, as that’s where most of the builder-ish stuff is. Recast is more responsible for how things are printed out, rememberish states of modified nodes, etc.
Thanks, I’ll give that a try! I was trying to accomplish this using
j.importSpecifier()
to create a new import specifier and then replace the existing one, but I guess your approach here is to just modify the existing one. That makes sense, thanks for the tip.That said, it still seems like maybe
j.importSpecifier()
should be able to create a type import, right? So, I’ll leave this feature request open for now.