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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
=== tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts ===
// String indexer types constrain the types of named properties in their containing type
interface MyString extends String {
>MyString : Symbol(MyString, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 0, 0))
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
foo: number;
>foo : Symbol(MyString.foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 2, 35))
}
class C {
>C : Symbol(C, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 4, 1))
[x: string]: string;
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 7, 5))
constructor() { } // ok
a: string; // ok
>a : Symbol(C.a, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 9, 21))
b: number; // error
>b : Symbol(C.b, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 11, 14))
c: () => {} // error
>c : Symbol(C.c, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 12, 14))
"d": string; // ok
>"d" : Symbol(C["d"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 13, 15))
"e": number; // error
>"e" : Symbol(C["e"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 14, 16))
1.0: string; // ok
>1.0 : Symbol(C[1.0], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 15, 16))
2.0: number; // error
>2.0 : Symbol(C[2.0], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 16, 16))
"3.0": string; // ok
>"3.0" : Symbol(C["3.0"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 17, 16))
"4.0": number; // error
>"4.0" : Symbol(C["4.0"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 18, 18))
f: MyString; // error
>f : Symbol(C.f, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 19, 18))
>MyString : Symbol(MyString, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 0, 0))
get X() { // ok
>X : Symbol(C.X, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 20, 16), Decl(stringIndexerConstrainsPropertyDeclarations.ts, 24, 5))
return '';
}
set X(v) { } // ok
>X : Symbol(C.X, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 20, 16), Decl(stringIndexerConstrainsPropertyDeclarations.ts, 24, 5))
>v : Symbol(v, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 25, 10))
foo() { // error
>foo : Symbol(C.foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 25, 16))
return '';
}
static sa: number; // ok
>sa : Symbol(C.sa, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 29, 5))
static sb: string; // ok
>sb : Symbol(C.sb, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 31, 22))
static foo() { } // ok
>foo : Symbol(C.foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 32, 22))
static get X() { // ok
>X : Symbol(C.X, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 34, 20))
return 1;
}
}
interface I {
>I : Symbol(I, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 38, 1))
[x: string]: string;
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 41, 5))
a: string; // ok
>a : Symbol(I.a, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 41, 24))
b: number; // error
>b : Symbol(I.b, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 43, 14))
c: () => {} // error
>c : Symbol(I.c, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 44, 14))
"d": string; // ok
>"d" : Symbol(I["d"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 45, 15))
"e": number; // error
>"e" : Symbol(I["e"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 46, 16))
1.0: string; // ok
>1.0 : Symbol(I[1.0], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 47, 16))
2.0: number; // error
>2.0 : Symbol(I[2.0], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 48, 16))
(): string; // ok
(x): number // ok
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 51, 5))
foo(): string; // error
>foo : Symbol(I.foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 51, 15))
"3.0": string; // ok
>"3.0" : Symbol(I["3.0"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 52, 18))
"4.0": number; // error
>"4.0" : Symbol(I["4.0"], Decl(stringIndexerConstrainsPropertyDeclarations.ts, 53, 18))
f: MyString; // error
>f : Symbol(I.f, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 54, 18))
>MyString : Symbol(MyString, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 0, 0))
}
var a: {
>a : Symbol(a, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 58, 3))
[x: string]: string;
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 59, 5))
a: string; // ok
>a : Symbol(a, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 59, 24))
b: number; // error
>b : Symbol(b, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 61, 14))
c: () => {} // error
>c : Symbol(c, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 62, 14))
"d": string; // ok
>"d" : Symbol("d", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 63, 15))
"e": number; // error
>"e" : Symbol("e", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 64, 16))
1.0: string; // ok
>1.0 : Symbol(1.0, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 65, 16))
2.0: number; // error
>2.0 : Symbol(2.0, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 66, 16))
(): string; // ok
(x): number // ok
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 69, 5))
foo(): string; // error
>foo : Symbol(foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 69, 15))
"3.0": string; // ok
>"3.0" : Symbol("3.0", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 70, 18))
"4.0": number; // error
>"4.0" : Symbol("4.0", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 71, 18))
f: MyString; // error
>f : Symbol(f, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 72, 18))
>MyString : Symbol(MyString, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 0, 0))
}
// error
var b: { [x: string]: string; } = {
>b : Symbol(b, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 77, 3))
>x : Symbol(x, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 77, 10))
a: '',
>a : Symbol(a, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 77, 35))
b: 1,
>b : Symbol(b, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 78, 10))
c: () => { },
>c : Symbol(c, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 79, 9))
"d": '',
>"d" : Symbol("d", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 80, 17))
"e": 1,
>"e" : Symbol("e", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 81, 12))
1.0: '',
>1.0 : Symbol(1.0, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 82, 11))
2.0: 1,
>2.0 : Symbol(2.0, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 83, 12))
"3.0": '',
>"3.0" : Symbol("3.0", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 84, 11))
"4.0": 1,
>"4.0" : Symbol("4.0", Decl(stringIndexerConstrainsPropertyDeclarations.ts, 85, 14))
f: <MyString>null,
>f : Symbol(f, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 86, 13))
>MyString : Symbol(MyString, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 0, 0))
get X() {
>X : Symbol(X, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 87, 22), Decl(stringIndexerConstrainsPropertyDeclarations.ts, 91, 6))
return '';
},
set X(v) { },
>X : Symbol(X, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 87, 22), Decl(stringIndexerConstrainsPropertyDeclarations.ts, 91, 6))
>v : Symbol(v, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 92, 10))
foo() {
>foo : Symbol(foo, Decl(stringIndexerConstrainsPropertyDeclarations.ts, 92, 17))
return '';
}
}
|