Directives
Directives are file-level instructions that control imports and feature flags. They appear at the top of .ion files before any type declarations.
#import — Import Types
Import specific types from another module or file:
#import { User, Role } from "auth" #import { OrderItem } from "shop" service UserService() { GetUser(id: u4): User; // User is imported from "auth" module }
Module names reference external modules declared in ion.config.json. Only the listed types become available in the current scope. See Modules for more details on how the module system works.
Circular imports are forbidden. If module A imports from B and B imports from A, the compiler reports ION0040.
#use — Import File (Deprecated)
Deprecated. The #use directive is deprecated (ION0047). Use #import { Type } from "module" instead.
Legacy syntax for importing all types from a local file:
#use "common.ion" #use "models/user.ion"
Paths are relative to the current file's directory. All type declarations from the imported file become available in the current scope.
#feature — Feature Flags
Enable a feature module in the current file:
#feature "std" #feature "vector"
Maybe<T>, Array<T>, Partial<T>, standard attributes Vector2, Vector3, Vector4, Quaternion Features are also declared in ion.config.json. The #feature directive enables them at the file level.
Module System
Each .ion file is a module. The compiler processes all .ion files in the project directory and resolves imports across files. For external module dependencies, see the Modules guide.
- Parse all
.ionfiles - Resolve external module dependencies from ion.config.json
- Detect import cycles (ION0001, ION0040)
- Resolve type references across modules
- Validate and generate code