Issue Task Closed

#106300Use verbatim TypeScript module syntax

Benjamin Franzke 03/04/25, 11:37 updated 08/12/25, 14:35

Description

The TypeScript verbatim module syntax (available since TypeScript 5.0)
makes TypeScript import elision explicit instead of implicit by never
dropping import statements that import types only, allowing to
import from modules with side effects without the risk that TypeScript
might optimize the import away.

One of such “useful” side effects are web components, given following
Exmaple:

// Module import './my-component' would be optimized
// "away" by TypeScript, because only a type was imported.
// with tsconfig option "verbatimModuleSyntax: false"
import { MyComponentType } from './my-component'

const el: MyComponentType = mydocument.createElement('my-component');

With “verbatimModuleSyntax: true” the above code results in an error
and we have two options:

// Option 1) Import type and preserve the module import
import { type MyComponentType } from './my-component'

// Option 2) Import type and drop the module import
import type { MyComponentType } from './my-component'

In this case the desired option is 1) since we want the import from
@./my-component@ to be preserved, as we need the web component
that is provided as a side-effect (custom elements registry) of
the module.

See https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax for
more information.

Reviews 2