question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: allow creation of new typescript 4.5 type import

See original GitHub issue

There 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:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ElonVolocommented, Feb 13, 2022

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.

1reaction
IanVScommented, Feb 11, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found