Import aliases rename something you import so it fits better in the current file.
Two packages called render
Suppose two packages both export a function named render. You cannot import both as render because names must not collide.
import @blog { render as render_blog }
import @docs { render as render_docs }
blog_html = render_blog()
docs_html = render_docs()
Namespace aliases
You can also rename a whole namespace.
import @core/math as math
value = math.sin(1.0)
File-local scope
An import alias is visible only in the file where it is written. It does not change the exported name in the source file, and it is not automatically re-exported.
No shadowing
An alias cannot hide an existing name. If render is already declared in the file, import @other { render } is an error. Pick a different local name instead.
Import aliases rename an imported symbol for local use inside one file. They are distinct from type aliases and from public module re-export names.
Definition and syntax
A namespace alias changes the local name of an imported namespace:
import @core/math as math
A grouped symbol alias changes the local name of one imported binding:
import @core/math {
sin as sine,
PI as CIRCLE_PI,
}
Exact contract
- A namespace alias changes the namespace name visible in one file.
- A grouped symbol alias changes one imported binding visible in one file.
- The source declaration keeps its canonical exported identity.
- Ordinary import aliases are file-local.
- Ordinary import aliases are not automatically re-exported.
- Aliases work for every importable symbol category the import surface supports: functions, constants, structs, choices, type aliases and external package members.
- External package aliases follow the same local collision policy as source imports.
- Each grouped entry is renamed separately.
- A grouped import cannot use one trailing group-level alias.
Collision rules
Import aliases must not collide with any visible name in the same file, including:
- same-file declarations
- other imports
- other aliases
- type aliases
- builtins
- preluded names
Aliases do not shadow an existing visible name. A collision is a compile error.
render || -> String:
return "local"
;
import @other { render }
Resolve the collision by renaming the import.
import @other { render as render_other }
Leading-case warnings
An alias whose leading case differs from the imported symbol's leading case produces a warning. The warning is intentionally simple: it catches obvious type-versus-value naming drift without trying to classify every naming convention.
import @core/math { sin as Sine }
import @core/math { PI as pi }
Namespace aliases
Use a namespace alias when the imported path would be awkward to repeat or when two imported namespaces share a basename.
import @core/math as math
import @core/text as text
value = math.sin(1.0)
length = text.length("hello")
Grouped symbol aliases
Use grouped symbol aliases when two packages export the same name.
import @blog { render as render_blog }
import @docs { render as render_docs }
blog_html = render_blog()
docs_html = render_docs()
A grouped import cannot use a single alias for the whole group.
import @components { Button, Card } as Ui
import @components {
Button as UiButton,
Card as UiCard,
}
Local and public-name distinction
An ordinary import alias is private to the importing file. A public name chosen in a module root's export surface is a different operation. Cross-module visibility is controlled by the module root's explicit export: surface. The normal module-root filename itself has no semantic role. The current export syntax is owned by Project Structure and Packages. Do not treat a local import alias as a public API rename.
import @models { User as ModelUser }
The local ModelUser is visible only in this file. A public rename belongs inside the module root's current explicit export: block. See Project Structure and Packages for the exact current form.
Import aliases with type aliases
A type alias may target an imported type alias.
import @models { User as ExternalUser }
CurrentUser as ExternalUser
This combines a file-local import rename with a domain-specific type alias.
Related concepts
- For type aliases see the previous section.
- For payload capture aliases see the next section.
- For import syntax and module roots see Packages and Project Structure.