can1357/oh-my-pi · error · OmpTypeError

unknown alias "${name}"

Error message

unknown alias "${name}"

What it means

When building a scope's module/builder surface, `targetFor(name)` resolves a requested alias name through the scope's resolver. If the name is not defined in the scope, resolution returns undefined and omptype throws `unknown alias`. This surfaces when accessing a type that the scope never declared.

Source

Thrown at packages/omptype/src/type.ts:3910

		Reflect.set(schema, "$", scopeValue);
		Reflect.set(schema, "resolver", resolve);
		return schema;
	};
	const parseScoped = (definition: unknown): InternalType =>
		bind(makeType(withScopeConfig(parseDef(definition, resolve)), EMPTY_STEPS, scopeMeta));
	const scopedMatch = createMatchParser({
		parse: definition => parseScoped(definition) as unknown as BaseType,
		branches: [],
	});
	const scoped = Object.assign((definition: unknown) => parseScoped(definition), type, {
		fn: makeFn(resolve),
		match: scopedMatch,
		...naryStatics(resolve),
	}) as unknown as ScopedBuilder;

	const targetFor = (name: string): IR => {
		const resolved = resolve(name);
		if (resolved === undefined) throw new OmpTypeError(`unknown alias "${name}"`);
		return resolved.k === "alias" ? resolved.resolve() : resolved;
	};
	const schemaFor = (name: string): BaseType =>
		bind(makeType(withScopeConfig(targetFor(name)), EMPTY_STEPS, scopeMeta)) as unknown as BaseType;

	const bindModule = (names: readonly string[]): RuntimeModule => {
		const module = {} as RuntimeModule;
		Object.defineProperty(module, MODULE_SCOPE, { value: scopeValue });
		for (const name of names) {
			const entry = entries.get(name);
			if (entry === undefined) continue;
			if (entry.genericParameters !== undefined) {
				module[name] = genericFor(entry) as unknown as BaseType;
				continue;
			}
			const definition = materialize(entry);
			module[name] = isRuntimeModule(definition) ? definition : schemaFor(name);
		}

View on GitHub (pinned to 9690622007)

Solutions

  1. Add the missing key to the scope's alias object.
  2. Fix the typo/case in the name being accessed.
  3. Use `scope.import`/`export` to bring in aliases defined in other scopes.
  4. Enumerate the scope's available names (e.g. via the module exports) before accessing dynamically.

Example fix

// before
const $ = type.scope({ user: "string" }); $.type.usr
// after
const $ = type.scope({ user: "string" }); $.type.user
Defensive patterns

Strategy: try-catch

Validate before calling

const aliasExists = ($: ScopedBuilder, name: string) => name in $.export;

Try / catch

try { const t = scope.type[name as keyof typeof scope.type]; } catch (e) { if (e instanceof OmpTypeError && e.message.startsWith('unknown alias')) return null; throw e; }

Prevention

When it happens

Trigger: Accessing `myScope.type.Missing` or exporting a module for a name that is not a key in the scope's aliases; typos in scope keys vs. export lists; referencing an alias defined in a different scope without importing it.

Common situations: Refactoring scope keys without updating the exported module name list; case/typo mismatches (`UserId` vs `userId`); cross-scope references that were never added via `import`/`export` in the scope definition.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/8d021401fbbcc5c6. Report an issue: GitHub.