assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

`import type` syntax

Open trusktr opened this issue 2 years ago • 2 comments

In some cases like importing an interface, in portable mode, we don't want the output JS to include the type import. So for regular TypeScript projects we'd write this:

import type {SomeInterface} from 'somewhere'

but the import type currently causes an error with asc so we must write

import {SomeInterface} from 'somewhere'

which causes side effects when compiling to JS despite needing only a type.

When compiling to JS the import type allows the tsc compiler to strip the import statement (thus not instantiate everything in the module at JS runtime if only a type was needed).

asc would need to allow the syntax, then treat it the same as it already does (because AS already does tree shaking, so it is no issue in AS).

trusktr avatar Jun 11 '22 17:06 trusktr

I guess this PR may help with this: https://github.com/AssemblyScript/assemblyscript/pull/2150

MaxGraey avatar Jun 11 '22 18:06 MaxGraey

Yeah, that seems perfect, since all mechanics for AS are in place

trusktr avatar Jun 11 '22 18:06 trusktr