mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
65 lines
2.3 KiB
Plaintext
65 lines
2.3 KiB
Plaintext
inOperatorWithValidOperands.ts(26,20): error TS2322: Type 'T' is not assignable to type 'object'.
|
|
inOperatorWithValidOperands.ts(30,20): error TS2322: Type 'T | U' is not assignable to type 'object'.
|
|
Type 'T' is not assignable to type 'object'.
|
|
inOperatorWithValidOperands.ts(34,20): error TS2322: Type 'object | T' is not assignable to type 'object'.
|
|
Type 'T' is not assignable to type 'object'.
|
|
|
|
|
|
==== inOperatorWithValidOperands.ts (3 errors) ====
|
|
var x: any;
|
|
|
|
// valid left operands
|
|
// the left operand is required to be of type Any, the String primitive type, or the Number primitive type
|
|
declare var a1: string;
|
|
declare var a2: number;
|
|
declare var a3: string | number | symbol;
|
|
declare var a4: any;
|
|
|
|
var ra1 = x in x;
|
|
var ra2 = a1 in x;
|
|
var ra3 = a2 in x;
|
|
var ra4 = '' in x;
|
|
var ra5 = 0 in x;
|
|
var ra6 = a3 in x;
|
|
var ra7 = a4 in x;
|
|
|
|
// valid right operands
|
|
// the right operand is required to be of type Any, an object type, or a type parameter type
|
|
declare var b1: {};
|
|
|
|
var rb1 = x in b1;
|
|
var rb2 = x in {};
|
|
|
|
function foo<T>(t: T) {
|
|
var rb3 = x in t;
|
|
~
|
|
!!! error TS2322: Type 'T' is not assignable to type 'object'.
|
|
!!! related TS2208 inOperatorWithValidOperands.ts:25:14: This type parameter might need an `extends object` constraint.
|
|
}
|
|
|
|
function unionCase<T, U>(t: T | U) {
|
|
var rb4 = x in t;
|
|
~
|
|
!!! error TS2322: Type 'T | U' is not assignable to type 'object'.
|
|
!!! error TS2322: Type 'T' is not assignable to type 'object'.
|
|
!!! related TS2208 inOperatorWithValidOperands.ts:29:20: This type parameter might need an `extends object` constraint.
|
|
}
|
|
|
|
function unionCase2<T>(t: T | object) {
|
|
var rb5 = x in t;
|
|
~
|
|
!!! error TS2322: Type 'object | T' is not assignable to type 'object'.
|
|
!!! error TS2322: Type 'T' is not assignable to type 'object'.
|
|
!!! related TS2208 inOperatorWithValidOperands.ts:33:21: This type parameter might need an `extends object` constraint.
|
|
}
|
|
|
|
interface X { x: number }
|
|
interface Y { y: number }
|
|
|
|
declare var c1: X | Y;
|
|
declare var c2: X;
|
|
declare var c3: Y;
|
|
|
|
var rc1 = x in c1;
|
|
var rc2 = x in (c2 || c3);
|
|
|