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

fix(lsp): code action imports of types are import type #10814

Closed
wants to merge 1 commit into from

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Jun 1, 2021

Fixes: #10776

@kitsonk kitsonk requested a review from lucacasonato June 1, 2021 07:13
@lucacasonato
Copy link
Member

Wouldn't enabling "importsNotUsedAsValues": "error" result in more diagnostics than in the CLI (where this is not set to "error")?

I.e. wouldn't this error in LSP, but not deno run?

import { Foo } from "https://example.com/foo.ts";
const foo: Foo = { };

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 1, 2021

It does but, a) there is no other way to get TypeScript to import as import type when auto importing types, and b) while Deno CLI can run such code, it runs the risk of being "transpile unfriendly", so it encourages better code anyways. I would be for setting it to "error" for CLI as well, as it avoids some problems people can get themselves into (like doing an export * from "foo" that is doing a named import from some other module, which we have seen in the wild).

Given the module a.ts of:

export interface A {
  a: string;
}

export const a = "a";

The following would have no diagnostics:

import { A, a } from "./a.ts";

const b: A = {
  a,
};

console.log(a);

The following would also not have any diagnostics:

import type { A } from "./a.ts";

const b: A = {
  a: "a"
};

console.log(a);

The following would have This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'. for the import statement:

import { A } from "./a.ts";

const b: A = {
  a: "a"
};

console.log(a);

@lucacasonato
Copy link
Member

Mh - this feels like it would slot into a larger discussion about the importsNotUsedAsValues option. We used to have it set to "error" (#7413), but then reverted back to "remove" a few weeks later (#7800). The "remove" option is unambiguous already with isolatedModules: true, so I don't know.

Very hesitant to land this in LSP without also landing for the rest of CLI. But doing so would result in a lot of churn for users for no big benefit that I can see.

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 1, 2021

🤷 I won't lose any sleep over it. It was only because people were reporting it as an issue.

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 1, 2021

Let's close this, as the potential pain ain't worth the squeeze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lsp: Auto import types as type
2 participants