1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] ////
=== intersectionSatisfiesConstraint.ts ===
interface FirstInterface {
commonProperty: number
>commonProperty : number
}
interface SecondInterface {
commonProperty: number
>commonProperty : number
}
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
>myFirstFunction : <T extends FirstInterface | SecondInterface>(param1: T) => void
><T extends FirstInterface | SecondInterface>(param1: T) => { const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) mySecondFunction(newParam)} : <T extends FirstInterface | SecondInterface>(param1: T) => void
>param1 : T
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
>newParam : T & { otherProperty: number; }
>otherProperty : number
>Object.assign(param1, { otherProperty: 3 }) : T & { otherProperty: number; }
>Object.assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
>Object : ObjectConstructor
>assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
>param1 : T
>{ otherProperty: 3 } : { otherProperty: number; }
>otherProperty : number
>3 : 3
mySecondFunction(newParam)
>mySecondFunction(newParam) : { commonProperty: number; otherProperty: number; }
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
>newParam : (FirstInterface | SecondInterface) & { otherProperty: number; }
}
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
><T extends { commonProperty: number, otherProperty: number }>(newParam: T) => { return newParam} : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
>commonProperty : number
>otherProperty : number
>newParam : T
return newParam
>newParam : T
}
|