#no-ambiguous-success-type
Disallows non-specific types in the success position of Result, ResultAsync, and ResultMaybeAsync.
#Rule details
Using vague types like unknown, any, object, or {} as the success type of a Result hides information from callers. Always use a concrete type so that consumers know exactly what they receive on success.
The following types are disallowed in the success position: unknown, any, object, {}
#Incorrect
import { import Result Result } from '@praha/byethrow';
// ❌ using unknown
type type Result1 = Result.Success<unknown> | Result.Failure<Error> Result1 = import Result Result .type Result<T, E> = Result.Success<T> | Result.Failure<E>A union type representing either a success or a failure.
@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@exampleimport { Result } from '@praha/byethrow';
const doSomething = (): Result.Result<number, string> => {
return Math.random() > 0.5
? { type: 'Success', value: 10 }
: { type: 'Failure', error: 'Oops' };
};
@categoryCore Types Result <unknown, Error>;
// ❌ using any
type type Result2 = Result.Failure<Error> | Result.Success<any> Result2 = import Result Result .type Result<T, E> = Result.Success<T> | Result.Failure<E>A union type representing either a success or a failure.
@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@exampleimport { Result } from '@praha/byethrow';
const doSomething = (): Result.Result<number, string> => {
return Math.random() > 0.5
? { type: 'Success', value: 10 }
: { type: 'Failure', error: 'Oops' };
};
@categoryCore Types Result <any, Error>;
// ❌ using object
type type Result3 = Result.Failure<Error> | Result.Success<object> Result3 = import Result Result .type Result<T, E> = Result.Success<T> | Result.Failure<E>A union type representing either a success or a failure.
@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@exampleimport { Result } from '@praha/byethrow';
const doSomething = (): Result.Result<number, string> => {
return Math.random() > 0.5
? { type: 'Success', value: 10 }
: { type: 'Failure', error: 'Oops' };
};
@categoryCore Types Result <object, Error>;#Correct
import { import Result Result } from '@praha/byethrow';
// ✅ using a concrete type
type type Result1 = Result.Success<{
id: string;
}> | Result.Failure<Error>
Result1 = import Result Result .type Result<T, E> = Result.Success<T> | Result.Failure<E>A union type representing either a success or a failure.
@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@exampleimport { Result } from '@praha/byethrow';
const doSomething = (): Result.Result<number, string> => {
return Math.random() > 0.5
? { type: 'Success', value: 10 }
: { type: 'Failure', error: 'Oops' };
};
@categoryCore Types Result <{ id: string id : string }, Error>;
// ✅ void is allowed for operations that return no value
type type Result2 = Result.Failure<Error> | Result.Success<void> Result2 = import Result Result .type Result<T, E> = Result.Success<T> | Result.Failure<E>A union type representing either a success or a failure.
@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@exampleimport { Result } from '@praha/byethrow';
const doSomething = (): Result.Result<number, string> => {
return Math.random() > 0.5
? { type: 'Success', value: 10 }
: { type: 'Failure', error: 'Oops' };
};
@categoryCore Types Result <void, Error>;