ЗП
[Either a b] -> `Either a [b]
?)Size: a a a
ЗП
[Either a b] -> `Either a [b]
?)˸A
function combine<T extends unknown[]>(results: ResultsOfT<T>): Result<T> {
for (const result of results) {
if (result.isErr) return result;
}
return Result.ok((results as OksOfT<T>).map(result => result.value) as T);
}
ЗП
˸A
function combine<T extends unknown[]>(results: ResultsOfT<T>): Result<T> {
for (const result of results) {
if (result.isErr) return result;
}
return Result.ok((results as OksOfT<T>).map(result => result.value) as T);
}
as T
PS
PS
as T
const result = Result.combine<[Gender, Cm]>([validateGender(), validateHeight()]);
const [gender, height] = result.value;
˸A
const result = Result.combine<[Gender, Cm]>([validateGender(), validateHeight()]);
const [gender, height] = result.value;
PS
˸A
ЗП
˸A
ЗП
˸A
ЗП
LK
interface Prop1 {
prop1: number;
otherProp: number;
}
interface Prop2 {
prop2: number;
}
type Prop = Prop1 | Prop2;
const fn (payload: Prop) => {};
fn( { prop2: 2 } ) // ok
fn( { prop2: 2, otherProp: 3 } ) // фигня
Prop1
или только Prop2
˸A
fn (payload: Prop2)
, нет?LK
fn (payload: Prop2)
, нет?˸A
LK
ЗП
interface Prop1 {
prop1: number;
otherProp: number;
}
interface Prop2 {
prop2: number;
}
type Prop = Prop1 | Prop2;
const fn (payload: Prop) => {};
fn( { prop2: 2 } ) // ok
fn( { prop2: 2, otherProp: 3 } ) // фигня
Prop1
или только Prop2