Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript auto-import put comma in wrong position #40219

Closed
chengB12 opened this issue Aug 24, 2020 · 8 comments · Fixed by #40273
Closed

Typescript auto-import put comma in wrong position #40219

chengB12 opened this issue Aug 24, 2020 · 8 comments · Fixed by #40273
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@chengB12
Copy link

TypeScript Version: 4.1.0-dev.20200823
Visual Studio Code Version: 1.48.1

Search Terms: import comma

Code

import { Foo1,
   Foo2, Foo3,
   Foo4, Foo5,
} from 'foo'

export default {
     foo6: {} as Foo6
}

Expected behavior:
When prompted Quick Fix => click "Add 'Foo6' to existing import declaration 'foo', and click auto-import
The import declaration shall be

import { Foo1,
   Foo2, Foo3,
   Foo4, Foo5, Foo6,
} from 'foo'

Actual behavior:

import { Foo1,
   Foo2, Foo3,
   Foo4, Foo5,, Foo6
} from 'foo'

image
image

@chengB12
Copy link
Author

chengB12 commented Aug 24, 2020

This is can be reproduced when new imported is last thing in that line, when '} from 'foo' is on newline, and having a trailing comma.

It looks like auto-import didn't consider trailing comma:

import {
   foo1
} from 'foo'
// ==>
import {
   foo1, foo2
} from 'foo'

without trailing comma, auto-import does thing exactly correct, however, with trailing comma, it will wrong format

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 24, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.1.0 milestone Aug 24, 2020
@j-oliveras
Copy link
Contributor

Duplicated/related to #39717?

@chengB12
Copy link
Author

Duplicated/related to #39717?

Yes, it looks duplicate, I think because I searched for open issues, and that issue was closed, so I missed that.

And previous closed because can't reproduce, I find a way to reproduce

@andrewbranch
Copy link
Member

I don’t know what to tell you 😐

Kapture 2020-08-25 at 16 46 32

@andrewbranch andrewbranch added Needs More Info The issue still hasn't been fully clarified and removed Bug A bug in TypeScript labels Aug 25, 2020
@chengB12
Copy link
Author

well, I can conform ts 4.1.0-dev.20200824, vs code 1.48.2 still has this issue

@chengB12
Copy link
Author

I reproduced it with 11 imports:

import {
    Foo1, Foo2,
    Foo3,
    Foo4,
    Foo5,
    Foo6,
    Foo7,
    Foo8,
    Foo9,
    Foo10,, Foo11
} from './foo'

export default {
    foo1: 1 as Foo1,
    foo2: 2 as Foo2,
    foo11: 11 as Foo11,
}

@chengB12
Copy link
Author

before
image
after
image

@andrewbranch
Copy link
Member

Ok, that one repros for me. Thanks @chengB12

@andrewbranch andrewbranch added Bug A bug in TypeScript and removed Needs More Info The issue still hasn't been fully clarified labels Aug 26, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 26, 2020
@RyanCavanaugh RyanCavanaugh added Rescheduled This issue was previously scheduled to an earlier milestone and removed Rescheduled This issue was previously scheduled to an earlier milestone labels Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants