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
|
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(21,5): error TS2322: Type 'T' is not assignable to type 'boolean'.
Type 'TableClass<any>' is not assignable to type 'boolean'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(22,5): error TS2322: Type 'T' is not assignable to type 'string | number'.
Type 'TableClass<any>' is not assignable to type 'string | number'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(23,5): error TS2322: Type 'T' is not assignable to type 'string | Something'.
Type 'TableClass<any>' is not assignable to type 'string | Something'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(24,5): error TS2322: Type 'T' is not assignable to type 'Something | SomethingElse'.
Type 'TableClass<any>' is not assignable to type 'Something | SomethingElse'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(28,5): error TS2322: Type 'T' is not assignable to type 'boolean'.
Type 'TableClass<any>' is not assignable to type 'boolean'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(29,5): error TS2322: Type 'T' is not assignable to type 'string | number'.
Type 'TableClass<any>' is not assignable to type 'string | number'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(30,5): error TS2322: Type 'T' is not assignable to type 'string | Something'.
Type 'TableClass<any>' is not assignable to type 'string | Something'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(31,5): error TS2322: Type 'T' is not assignable to type 'Something | SomethingElse'.
Type 'TableClass<any>' is not assignable to type 'Something | SomethingElse'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(35,1): error TS2322: Type 'Table' is not assignable to type 'boolean'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(36,1): error TS2322: Type 'Table' is not assignable to type 'string | number'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(37,1): error TS2322: Type 'Table' is not assignable to type 'string | Something'.
tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts(38,1): error TS2322: Type 'Table' is not assignable to type 'Something | SomethingElse'.
==== tests/cases/compiler/typeVariableConstraintedToAliasNotAssignableToUnion.ts (12 errors) ====
declare class TableClass<S = any> {
_field: S;
}
export type Table = TableClass;
interface Something {
prop: number;
}
interface SomethingElse {
prop2: string;
}
declare let aBoolean: boolean;
declare let aStringOrNumber: string | number;
declare let aStringOrSomething: string | Something;
declare let someUnion: Something | SomethingElse;
function fn<T extends Table>(o: T) {
aBoolean = o;
~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'boolean'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'boolean'.
aStringOrNumber = o;
~~~~~~~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'string | number'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'string | number'.
aStringOrSomething = o;
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'string | Something'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'string | Something'.
someUnion = o;
~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'Something | SomethingElse'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'Something | SomethingElse'.
}
function fn2<T extends TableClass>(o: T) {
aBoolean = o;
~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'boolean'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'boolean'.
aStringOrNumber = o;
~~~~~~~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'string | number'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'string | number'.
aStringOrSomething = o;
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'string | Something'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'string | Something'.
someUnion = o;
~~~~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'Something | SomethingElse'.
!!! error TS2322: Type 'TableClass<any>' is not assignable to type 'Something | SomethingElse'.
}
declare const o: Table;
aBoolean = o;
~~~~~~~~
!!! error TS2322: Type 'Table' is not assignable to type 'boolean'.
aStringOrNumber = o;
~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Table' is not assignable to type 'string | number'.
aStringOrSomething = o;
~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Table' is not assignable to type 'string | Something'.
someUnion = o;
~~~~~~~~~
!!! error TS2322: Type 'Table' is not assignable to type 'Something | SomethingElse'.
|