Skip to content

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"
Feature Provides
std All primitive types, Maybe<T>, Array<T>, Partial<T>, standard attributes
vector Vector2, Vector3, Vector4, Quaternion
orleans Microsoft Orleans grain-aware code generation

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.

  1. Parse all .ion files
  2. Resolve external module dependencies from ion.config.json
  3. Detect import cycles (ION0001, ION0040)
  4. Resolve type references across modules
  5. Validate and generate code