Skip to content

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

@trusktr

Description

@trusktr

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

Metadata

Metadata

Assignees

Labels

cliCLI related issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions