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

Auto imports default to import type #687

Closed
madeleineostoja opened this issue Nov 24, 2020 · 6 comments
Closed

Auto imports default to import type #687

madeleineostoja opened this issue Nov 24, 2020 · 6 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@madeleineostoja
Copy link

Describe the bug
Auto imports for Typescript modules in Svelte components always default to import type { thing } from './thing.ts', even though I'm not importing types.

To Reproduce

  1. Create a typescript module
  2. Auto-import it into a Svelte component from intellisense suggestions
  3. See it gets imported as a type

Expected behavior
Auto imports should only be imported as a type if you are explicitly importing an eported type.

System (please complete the following information):

  • OS: MacOS Big Sur
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode
@madeleineostoja madeleineostoja added the bug Something isn't working label Nov 24, 2020
@jasonlyu123
Copy link
Member

Can you provide more info? At what condition does it import it as type and what are you importing?

@madeleineostoja
Copy link
Author

@jasonlyu123 All non-Svelte Typescript imports (functions, constants, etc) are imported as types, and I'm importing from intellisense suggestions when writing a component.

Is that what you meant? Happy to provide any other details.

@jasonlyu123
Copy link
Member

Yeah, that's what I meant, thanks. But I can't reproduce it. I only see the import type when annotating type.

// Component.svelte
import type { abc  } from './abc';
export let a: typeof abc;
// abc.ts
export function abc() { }

Can you try it on a fresh project and see if it exist?
Also, you can try if adding this to the compilerOptions of your tsconfig.json and restart your language-server to see if it make any difference.

"importsNotUsedAsValues": "remove",

@madeleineostoja
Copy link
Author

madeleineostoja commented Nov 25, 2020

Sorry I think I've narrowed it down more — seems to happen consistently when importing within an attribute string (eg: in class, for constants and CSS-in-JS).

Setting importsNotUsedAsValues to remove seems to fix it, but then you lose the errors when using a regular import as a type.

@dummdidumm
Copy link
Member

dummdidumm commented Nov 25, 2020

I still can't reproduce this given your description. Please post a snippet with a Svelte file, | as the character where your cursor is, and the TS file snippet where the variable is imported from.

@mcmxcdev
Copy link

mcmxcdev commented Dec 1, 2020

I also had this happening today for a simple .ts file.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Dec 22, 2020
By checking if import happens outside of script tags. If so, always remove it
sveltejs#687
dummdidumm added a commit that referenced this issue Dec 30, 2020
By checking if import happens outside of script tags. If so, always remove it
#687
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

4 participants