assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Skip "type" keyword during import declarations

Open MaxGraey opened this issue 2 years ago • 5 comments

Support following declarations:

import type { Foo } from "./foo";
import type * as Foo from "./foo";

This will introduced in TS 4.5 so support this as well:

import { type Foo, Boo } from "./foo";
import { Boo, type Foo } from "./foo";
  • [x] I've read the contributing guidelines
  • [x] I've added my name and email to the NOTICE file

MaxGraey avatar Nov 17 '21 17:11 MaxGraey

It may be worth to note that these behave differently in between TS and AS, in that TS will not include the respective source file, while AS always will. This can be unexpected, particularly since using the type keyword is typically done for this exact purpose. So there seems to be a tension here, and I am not sure that the desire to support the syntax outweighs the risks.

Perhaps, a compromise could be to display a warning to inform the developer that the syntax is supported, but has different semantics?

dcodeIO avatar Nov 18 '21 13:11 dcodeIO

In terms of TS, it's just speeding up type checking. Behaviour does not change much, just appear some restrictions. For AS, these restrictions do not make much sense. At least for now, but I wonder btw if we could also speedup / simplify / skip some checks with such notation? So I don't see much point in displaying a warning, as it's more of a constraint for TS, but not for AS.

MaxGraey avatar Nov 18 '21 13:11 MaxGraey

Hmm, so is my understanding wrong that this is mainly there to force elision, i.e., that code / top-level statements etc. of the other file doesn't matter / execute? I believe I got that from the relevant announcement. In more familiar terms, it seems that import preserves side effects, while import type is deliberately used so it does not.

dcodeIO avatar Nov 18 '21 16:11 dcodeIO

It not forces. It just hint which means imported name will uses only as type but not as object / class (for constructing, sub-classing or accessing to some static field / method).

MaxGraey avatar Nov 18 '21 16:11 MaxGraey

closes #2317

trusktr avatar Jun 11 '22 18:06 trusktr

Any news? :)

mkoch-otto avatar Aug 18 '23 13:08 mkoch-otto

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Nov 14 '23 23:11 github-actions[bot]

This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.

github-actions[bot] avatar Nov 22 '23 23:11 github-actions[bot]