RFC: Improving support for auto-imports in an Analog SFC #901
Replies: 4 comments 1 reply
-
It looks like we can use any key in the interface ImportAttributes {
[key: string]: string;
} If we go with import attributes I propose using it more broadly to replace some aspects of The Example: <script lang="ts">
import DefaultFromLib from '@external/lib' with { meta: 'imports' };
import { FormsModule } from '@angular/forms' with { meta: 'imports' };
import { StateService } from './data-access/state.service' with { meta: 'providers' }
import { myFunc } from './somewhere' with { meta: 'exposes' }
</script> |
Beta Was this translation helpful? Give feedback.
-
happy with import attributes |
Beta Was this translation helpful? Give feedback.
-
Import attributes for the win |
Beta Was this translation helpful? Give feedback.
-
Sorry for asking, maybe a noob question but just wanted to ask, how would import attributes solve this problem? |
Beta Was this translation helpful? Give feedback.
-
For an Analog SFC, we support auto-adding of
.analog
files to theimports
array of the underlying component.We do this by identifying the filename of the originating analog file. This works well for importing single files. It does not work for analog files imported from libraries or barrel files
To resolve this issue we are looking at using import attributes:
Import Attributes (Stage 3 proposal, available in TypeScript 5.3)
Import attributes are supported in TypeScript 5.3+ and allow us to use an existing standard for imports that declares them available for the template
One caveat is that non-template imports could not be included in the same import block
Alternatives
Import analysis with ts-morph
Currently, we are loading analog SFCs in ts-morph to compile them into TypeScript source. We could use some analysis based on Import Declarations but this approach is prone to errors and performance implications.
Template Imports
Another alternative would be to declare the imports inside the template block that are made available to the template
or
This has a pitfall of making it hard to parse with IDEs already supporting Angular and Analog component authoring and syntax highlighting, including an upcoming release of WebStorm.
Beta Was this translation helpful? Give feedback.
All reactions