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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
|
=== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/stringLiteralTypeIsSubtypeOfString.ts ===
// string literal types are subtypes of string, any
// ok
function f1(x: 'a');
>f1 : { (x: "a"): any; (x: string): any; }
>x : "a"
function f1(x: string);
>f1 : { (x: "a"): any; (x: string): any; }
>x : string
function f1(x: string) { }
>f1 : { (x: "a"): any; (x: string): any; }
>x : string
// ok
function f2(x: 'a');
>f2 : { (x: "a"): any; (x: any): any; }
>x : "a"
function f2(x: any);
>f2 : { (x: "a"): any; (x: any): any; }
>x : any
function f2(x: any) { }
>f2 : { (x: "a"): any; (x: any): any; }
>x : any
// errors
function f3(x: 'a');
>f3 : { (x: "a"): any; (x: Object): any; }
>x : "a"
function f3(x: Object);
>f3 : { (x: "a"): any; (x: Object): any; }
>x : Object
function f3(x: any) { }
>f3 : { (x: "a"): any; (x: Object): any; }
>x : any
function f4(x: 'a');
>f4 : { (x: "a"): any; (x: {}): any; }
>x : "a"
function f4(x: {});
>f4 : { (x: "a"): any; (x: {}): any; }
>x : {}
function f4(x: any) { }
>f4 : { (x: "a"): any; (x: {}): any; }
>x : any
function f5(x: 'a');
>f5 : { (x: "a"): any; (x: number): any; }
>x : "a"
function f5(x: number);
>f5 : { (x: "a"): any; (x: number): any; }
>x : number
function f5(x: any) { }
>f5 : { (x: "a"): any; (x: number): any; }
>x : any
function f6(x: 'a');
>f6 : { (x: "a"): any; (x: boolean): any; }
>x : "a"
function f6(x: boolean);
>f6 : { (x: "a"): any; (x: boolean): any; }
>x : boolean
function f6(x: any) { }
>f6 : { (x: "a"): any; (x: boolean): any; }
>x : any
function f7(x: 'a');
>f7 : { (x: "a"): any; (x: Date): any; }
>x : "a"
function f7(x: Date);
>f7 : { (x: "a"): any; (x: Date): any; }
>x : Date
function f7(x: any) { }
>f7 : { (x: "a"): any; (x: Date): any; }
>x : any
function f8(x: 'a');
>f8 : { (x: "a"): any; (x: RegExp): any; }
>x : "a"
function f8(x: RegExp);
>f8 : { (x: "a"): any; (x: RegExp): any; }
>x : RegExp
function f8(x: any) { }
>f8 : { (x: "a"): any; (x: RegExp): any; }
>x : any
function f9(x: 'a');
>f9 : { (x: "a"): any; (x: () => {}): any; }
>x : "a"
function f9(x: () => {});
>f9 : { (x: "a"): any; (x: () => {}): any; }
>x : () => {}
function f9(x: any) { }
>f9 : { (x: "a"): any; (x: () => {}): any; }
>x : any
class C implements String {
>C : C
toString(): string { return null; }
>toString : () => string
>null : null
charAt(pos: number): string { return null; }
>charAt : (pos: number) => string
>pos : number
>null : null
charCodeAt(index: number): number { return null; }
>charCodeAt : (index: number) => number
>index : number
>null : null
concat(...strings: string[]): string { return null; }
>concat : (...strings: string[]) => string
>strings : string[]
>null : null
indexOf(searchString: string, position?: number): number { return null; }
>indexOf : (searchString: string, position?: number) => number
>searchString : string
>position : number
>null : null
lastIndexOf(searchString: string, position?: number): number { return null; }
>lastIndexOf : (searchString: string, position?: number) => number
>searchString : string
>position : number
>null : null
localeCompare(that: string): number { return null; }
>localeCompare : (that: string) => number
>that : string
>null : null
match(regexp: any): string[] { return null; }
>match : (regexp: any) => string[]
>regexp : any
>null : null
replace(searchValue: any, replaceValue: any): string { return null; }
>replace : (searchValue: any, replaceValue: any) => string
>searchValue : any
>replaceValue : any
>null : null
search(regexp: any): number { return null; }
>search : (regexp: any) => number
>regexp : any
>null : null
slice(start?: number, end?: number): string { return null; }
>slice : (start?: number, end?: number) => string
>start : number
>end : number
>null : null
split(separator: any, limit?: number): string[] { return null; }
>split : (separator: any, limit?: number) => string[]
>separator : any
>limit : number
>null : null
substring(start: number, end?: number): string { return null; }
>substring : (start: number, end?: number) => string
>start : number
>end : number
>null : null
toLowerCase(): string { return null; }
>toLowerCase : () => string
>null : null
toLocaleLowerCase(): string { return null; }
>toLocaleLowerCase : () => string
>null : null
toUpperCase(): string { return null; }
>toUpperCase : () => string
>null : null
toLocaleUpperCase(): string { return null; }
>toLocaleUpperCase : () => string
>null : null
trim(): string { return null; }
>trim : () => string
>null : null
length: number;
>length : number
substr(from: number, length?: number): string { return null; }
>substr : (from: number, length?: number) => string
>from : number
>length : number
>null : null
valueOf(): string { return null; }
>valueOf : () => string
>null : null
[index: number]: string;
>index : number
}
// BUG 831846
function f10(x: 'a');
>f10 : { (x: "a"): any; (x: C): any; }
>x : "a"
function f10(x: C);
>f10 : { (x: "a"): any; (x: C): any; }
>x : C
function f10(x: any) { }
>f10 : { (x: "a"): any; (x: C): any; }
>x : any
interface I extends String {
foo: string;
>foo : string
}
// BUG 831846
function f11(x: 'a');
>f11 : { (x: "a"): any; (x: I): any; }
>x : "a"
function f11(x: I);
>f11 : { (x: "a"): any; (x: I): any; }
>x : I
function f11(x: any) { }
>f11 : { (x: "a"): any; (x: I): any; }
>x : any
function f12<T>(x: 'a');
>f12 : { <T>(x: "a"): any; <T>(x: T): any; }
>x : "a"
function f12<T>(x: T);
>f12 : { <T>(x: "a"): any; <T>(x: T): any; }
>x : T
function f12<T>(x: any) { }
>f12 : { <T>(x: "a"): any; <T>(x: T): any; }
>x : any
function f13<T extends String>(x: 'a');
>f13 : { <T extends String>(x: "a"): any; <T extends String>(x: T): any; }
>x : "a"
function f13<T extends String>(x: T);
>f13 : { <T extends String>(x: "a"): any; <T extends String>(x: T): any; }
>x : T
function f13<T extends String>(x: any) { }
>f13 : { <T extends String>(x: "a"): any; <T extends String>(x: T): any; }
>x : any
enum E { A }
>E : E
>A : E.A
function f14(x: 'a');
>f14 : { (x: "a"): any; (x: E): any; }
>x : "a"
function f14(x: E);
>f14 : { (x: "a"): any; (x: E): any; }
>x : E
function f14(x: any) { }
>f14 : { (x: "a"): any; (x: E): any; }
>x : any
function f15<T, U extends T>(x: 'a');
>f15 : { <T, U extends T>(x: "a"): any; <T, U extends T>(x: U): any; }
>x : "a"
function f15<T, U extends T>(x: U);
>f15 : { <T, U extends T>(x: "a"): any; <T, U extends T>(x: U): any; }
>x : U
function f15<T, U extends T>(x: any) { }
>f15 : { <T, U extends T>(x: "a"): any; <T, U extends T>(x: U): any; }
>x : any
function f16<T extends String, U extends T>(x: 'a');
>f16 : { <T extends String, U extends T>(x: "a"): any; <T extends String, U extends T>(x: U): any; }
>x : "a"
function f16<T extends String, U extends T>(x: U);
>f16 : { <T extends String, U extends T>(x: "a"): any; <T extends String, U extends T>(x: U): any; }
>x : U
function f16<T extends String, U extends T>(x: any) { }
>f16 : { <T extends String, U extends T>(x: "a"): any; <T extends String, U extends T>(x: U): any; }
>x : any
|