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 48 49 50 51 52 53 54 55 56 57 58 59 60
|
=== tests/cases/conformance/types/intersection/intersectionAsWeakTypeSource.ts ===
interface X { x: string }
>x : string
interface Y { y: number }
>y : number
interface Z { z?: boolean }
>z : boolean
type XY = X & Y;
>XY : XY
const xy: XY = {x: 'x', y: 10};
>xy : XY
>{x: 'x', y: 10} : { x: string; y: number; }
>x : string
>'x' : "x"
>y : number
>10 : 10
const z1: Z = xy; // error, {xy} doesn't overlap with {z}
>z1 : Z
>xy : XY
interface ViewStyle {
view: number
>view : number
styleMedia: string
>styleMedia : string
}
type Brand<T> = number & { __brand: T }
>Brand : Brand<T>
>__brand : T
declare function create<T extends { [s: string]: ViewStyle }>(styles: T): { [P in keyof T]: Brand<T[P]> };
>create : <T extends { [s: string]: ViewStyle; }>(styles: T) => { [P in keyof T]: Brand<T[P]>; }
>s : string
>styles : T
const wrapped = create({ first: { view: 0, styleMedia: "???" } });
>wrapped : { first: Brand<{ view: number; styleMedia: string; }>; }
>create({ first: { view: 0, styleMedia: "???" } }) : { first: Brand<{ view: number; styleMedia: string; }>; }
>create : <T extends { [s: string]: ViewStyle; }>(styles: T) => { [P in keyof T]: Brand<T[P]>; }
>{ first: { view: 0, styleMedia: "???" } } : { first: { view: number; styleMedia: string; }; }
>first : { view: number; styleMedia: string; }
>{ view: 0, styleMedia: "???" } : { view: number; styleMedia: string; }
>view : number
>0 : 0
>styleMedia : string
>"???" : "???"
const vs: ViewStyle = wrapped.first // error, first is a branded number
>vs : ViewStyle
>wrapped.first : Brand<{ view: number; styleMedia: string; }>
>wrapped : { first: Brand<{ view: number; styleMedia: string; }>; }
>first : Brand<{ view: number; styleMedia: string; }>
|