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

Langium TypeScript output should use type imports for non-value imports #960

Closed
trusktr opened this issue Feb 25, 2023 · 0 comments · Fixed by #1018
Closed

Langium TypeScript output should use type imports for non-value imports #960

trusktr opened this issue Feb 25, 2023 · 0 comments · Fixed by #1018
Assignees
Labels
cli CLI related issue

Comments

@trusktr
Copy link

trusktr commented Feb 25, 2023

Currently if a user updates their tsconfig to have the option "importsNotUsedAsValues": "error", they will get a type error in generated code:

Screenshot 2023-02-25 at 12 29 57 PM

So what Langium can do is output type-only imports like the following, for anything that is type-only:

import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module } from 'langium';

This is nice because, when bundling a lib for release, we want to import only files that are actually used. This setting tells TypeScript that it can safely remove the import statement from the output because no values are actually used, it is only for type checking.

If someone does need a side-effect import (or the generated code does), while they have this option enabled, the way to do that would be like so:

import type {SomeType} from 'something-that-has-side-effects'
import 'something-that-has-side-effects' // This will be kept
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli CLI related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants