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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
=== tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts ===
type A = { a: string };
>A : { a: string; }
>a : string
type B = { b: string };
>B : { b: string; }
>b : string
declare let sa1: { x: A & B };
>sa1 : { x: A & B; }
>x : A & B
declare let sa2: { x: A } & { x: B };
>sa2 : { x: A; } & { x: B; }
>x : A
>x : B
declare let ta1: { [key: string]: A & B };
>ta1 : { [key: string]: A & B; }
>key : string
declare let ta2: { [key: string]: A } & { [key: string]: B };
>ta2 : { [key: string]: A; } & { [key: string]: B; }
>key : string
>key : string
ta1 = sa1;
>ta1 = sa1 : { x: A & B; }
>ta1 : { [key: string]: A & B; }
>sa1 : { x: A & B; }
ta1 = sa2;
>ta1 = sa2 : { x: A; } & { x: B; }
>ta1 : { [key: string]: A & B; }
>sa2 : { x: A; } & { x: B; }
ta2 = sa1;
>ta2 = sa1 : { x: A & B; }
>ta2 : { [key: string]: A; } & { [key: string]: B; }
>sa1 : { x: A & B; }
ta2 = sa2;
>ta2 = sa2 : { x: A; } & { x: B; }
>ta2 : { [key: string]: A; } & { [key: string]: B; }
>sa2 : { x: A; } & { x: B; }
declare let sb1: { x: A } & { y: B };
>sb1 : { x: A; } & { y: B; }
>x : A
>y : B
declare let tb1: { [key: string]: A };
>tb1 : { [key: string]: A; }
>key : string
tb1 = sb1; // Error
>tb1 = sb1 : { x: A; } & { y: B; }
>tb1 : { [key: string]: A; }
>sb1 : { x: A; } & { y: B; }
// Repro from #32484
type constr<Source, Tgt> = { [K in keyof Source]: string } & Pick<Tgt, Exclude<keyof Tgt, keyof Source>>;
>constr : constr<Source, Tgt>
type s = constr<{}, { [key: string]: { a: string } }>;
>s : {} & Pick<{ [key: string]: { a: string; }; }, string | number>
>key : string
>a : string
declare const q: s;
>q : s
q["asd"].a.substr(1);
>q["asd"].a.substr(1) : string
>q["asd"].a.substr : (from: number, length?: number | undefined) => string
>q["asd"].a : string
>q["asd"] : { a: string; }
>q : s
>"asd" : "asd"
>a : string
>substr : (from: number, length?: number | undefined) => string
>1 : 1
q["asd"].b; // Error
>q["asd"].b : any
>q["asd"] : { a: string; }
>q : s
>"asd" : "asd"
>b : any
const d: { [key: string]: {a: string, b: string} } = q; // Error
>d : { [key: string]: { a: string; b: string; }; }
>key : string
>a : string
>b : string
>q : s
// Repro from #32484
declare let ss: { a: string } & { b: number };
>ss : { a: string; } & { b: number; }
>a : string
>b : number
declare let tt: { [key: string]: string };
>tt : { [key: string]: string; }
>key : string
tt = ss; // Error
>tt = ss : { a: string; } & { b: number; }
>tt : { [key: string]: string; }
>ss : { a: string; } & { b: number; }
|