|
| 1 | +=== tests/cases/compiler/genericUnboundedTypeParamAssignability.ts === |
| 2 | +function f1<T>(o: T) { |
| 3 | +>f1 : Symbol(f1, Decl(genericUnboundedTypeParamAssignability.ts, 0, 0)) |
| 4 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 0, 12)) |
| 5 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 0, 15)) |
| 6 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 0, 12)) |
| 7 | + |
| 8 | + o.toString(); // error |
| 9 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 0, 15)) |
| 10 | +} |
| 11 | + |
| 12 | +function f2<T extends {}>(o: T) { |
| 13 | +>f2 : Symbol(f2, Decl(genericUnboundedTypeParamAssignability.ts, 2, 1)) |
| 14 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 4, 12)) |
| 15 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 4, 26)) |
| 16 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 4, 12)) |
| 17 | + |
| 18 | + o.toString(); // no error |
| 19 | +>o.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) |
| 20 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 4, 26)) |
| 21 | +>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) |
| 22 | +} |
| 23 | + |
| 24 | +function f3<T extends Record<string, any>>(o: T) { |
| 25 | +>f3 : Symbol(f3, Decl(genericUnboundedTypeParamAssignability.ts, 6, 1)) |
| 26 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 8, 12)) |
| 27 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 28 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 8, 43)) |
| 29 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 8, 12)) |
| 30 | + |
| 31 | + o.toString(); // no error |
| 32 | +>o.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) |
| 33 | +>o : Symbol(o, Decl(genericUnboundedTypeParamAssignability.ts, 8, 43)) |
| 34 | +>toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) |
| 35 | +} |
| 36 | + |
| 37 | +function user<T>(t: T) { |
| 38 | +>user : Symbol(user, Decl(genericUnboundedTypeParamAssignability.ts, 10, 1)) |
| 39 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 12, 14)) |
| 40 | +>t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) |
| 41 | +>T : Symbol(T, Decl(genericUnboundedTypeParamAssignability.ts, 12, 14)) |
| 42 | + |
| 43 | + f1(t); |
| 44 | +>f1 : Symbol(f1, Decl(genericUnboundedTypeParamAssignability.ts, 0, 0)) |
| 45 | +>t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) |
| 46 | + |
| 47 | + f2(t); // error in strict, unbounded T doesn't satisfy the constraint |
| 48 | +>f2 : Symbol(f2, Decl(genericUnboundedTypeParamAssignability.ts, 2, 1)) |
| 49 | +>t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) |
| 50 | + |
| 51 | + f3(t); // error in strict, unbounded T doesn't satisfy the constraint |
| 52 | +>f3 : Symbol(f3, Decl(genericUnboundedTypeParamAssignability.ts, 6, 1)) |
| 53 | +>t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) |
| 54 | + |
| 55 | + t.toString(); // error, for the same reason as f1() |
| 56 | +>t : Symbol(t, Decl(genericUnboundedTypeParamAssignability.ts, 12, 17)) |
| 57 | +} |
| 58 | + |
0 commit comments