Skip to content

no-unknown-in-result ​

Result<unknown, E>, Result<any, E>, Option<unknown> and Option<any> are not allowed.

Why: Result<T, E> is T | Err<E>. With T = unknown that union is just unknown: the error case disappears from the type, and callers are never forced to check for it. Guide: Absence.

ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type SettingError = Enum<{ Empty: {} }>;
const SettingError = constructors<SettingError>();

export function readSetting(raw: string): Result<unknown, SettingError> {
  return raw === "" ? err(SettingError.Empty()) : raw;
}
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type SettingError = Enum<{ Empty: {} }>;
const SettingError = constructors<SettingError>();

export function readSetting(raw: string): Result<unknown, SettingError> {
  return raw === "" ? err(({ tag: "Empty" } satisfies SettingError as SettingError)) : raw;
}

✅ Accepted: give the value a type

✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type SettingError = Enum<{ Empty: {} }>;
const SettingError = constructors<SettingError>();

export function readSetting(raw: string): Result<string, SettingError> {
  return raw === "" ? err(SettingError.Empty()) : raw;
}
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type SettingError = Enum<{ Empty: {} }>;
const SettingError = constructors<SettingError>();

export function readSetting(raw: string): Result<string, SettingError> {
  return raw === "" ? err(({ tag: "Empty" } satisfies SettingError as SettingError)) : raw;
}

When the value really is unknown data, validate it into a type with validate<T> first.

The same unknown comes from a type parameter that only the returned Result (or Option) names. Nothing passed to the function says what T is, so a call without a type argument (send("/ping"), not send<User>("/ping")) infers unknown for it, and the error type is lost there. The declaration is reported:

ts
import type { Result } from "@evobug_com/safe-ts-std/result";

type RequestError = { readonly status: number };

export declare function send<T>(path: string): Promise<Result<T, RequestError>>;

✅ Accepted: a default for the calls that don't say, or T from an argument

✓ Accepted0 diagnostics
ts
import type { Result } from "@evobug_com/safe-ts-std/result";

type RequestError = { readonly status: number };

export declare function send<T = undefined>(path: string): Promise<Result<T, RequestError>>;
export declare function load<T>(path: string, check: (value: unknown) => Result<T, RequestError>): Promise<Result<T, RequestError>>;

A type parameter that a parameter, this or another type parameter names is inferred from the call, and isn't reported. A default of unknown or any is reported like none. See Errors.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra