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.

3.0.1 incorrectly deleting required imports from typescript files

See original GitHub issue

Hi,

The 3.0.1 update seems to be incorrectly deleting required imports.

The following code demonstrates the issue:

If I have TypeScript:

import { NormalizedCacheObject } from 'apollo-cache-inmemory'
import AWSAppSyncClient from 'aws-appsync'

export class Foo {
  public constructor(private readonly appSyncClient: AWSAppSyncClient<NormalizedCacheObject>) {}
  
  getClient(): any {
    return this.appSyncClient
  }
}

with package.json

{
  "name": "scratch",
  "version": "1.0.0",
  "main": "index.js",
  "license": "UNLICENSED",
  "private": true,
  "scripts": {
    "prettier": "prettier --list-different \"**/*.{json,js,ts,yml,}\""
  },
  "resolutions": {
    "apollo-cache-inmemory": "^1.6.6"
  },
  "devDependencies": {
    "prettier": "^2.7.1",
    "prettier-plugin-organize-imports": "^3.0.1",
    "typescript": "^4.7.4"
  },
  "dependencies": {
    "apollo-cache-inmemory": "^1.6.6",
    "aws-appsync": "^4.1.7"
  }
}

then the import:

import AWSAppSyncClient from 'aws-appsync'

is flagged as needing to be deleted.

If I use 3.0.0 then the import is not flagged.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
simonhaenischcommented, Aug 8, 2022

Thanks for replying, the performance regression is being tracked in #67 now. Should be able to get a fix out today.

2reactions
askielboecommented, Aug 5, 2022

We have a similar issue when trying to upgrade from 3.0.0 to 3.0.1. Here is a minimal reproduction:

  1. Create an app using npx create-react-app organize-bug --template typescript

  2. Install prettier: npm i prettier prettier-plugin-organize-imports

  3. src/models/Tip.ts

export type Tip = {
  text: string
}
  1. src/App.tsx
import { Tip as TipModel } from "./models/Tip"

export const Tip = () => {
    const logTip = (tip: TipModel) => console.log(tip)
    logTip({text: "hello world"})
}
  1. Running prettier with prettier-plugin-organize-imports removes import { Tip as TipModel } from "./models/Tip":
npx prettier --check .
Checking formatting...
[warn] src/App.tsx
[warn] Code style issues found in the above file. Forgot to run Prettier?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Import code suggestions missing after upgrading to typescript ...
Try installing typescript@next into your project and switching VS Code to use it and see if the problem goes away.
Read more >
moving TypeScript files in explorer fails to update/prompt ...
Create an empty project with 2 typescript files, one importing from the other. In the explorer manually move the depended upon file to...
Read more >
TSConfig Reference - Docs on every TSConfig option
This technique lets you generate types ahead of time for the non-code source files. Imports then work naturally based off the source file's...
Read more >
July 2018 (version 1.26) - Visual Studio Code
Add all missing imports Quick Fix. The Add missing import Quick Fix can now be applied to all missing imports in a JavaScript/TypeScript...
Read more >
Firebase JavaScript SDK Release Notes - Google
json files for all published packages to make them compatible with TypeScript 4.7 support of Node.js ES modules. See Github issue #6300. Fixed...
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