diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8cee82c27af3..52e6862110f53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -41147,7 +41147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const modifiers = getTypeParameterModifiers(typeParameter) & (ModifierFlags.In | ModifierFlags.Out); if (modifiers) { const symbol = getSymbolOfDeclaration(node.parent); - if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Reference | ObjectFlags.Anonymous | ObjectFlags.Mapped))) { + if (isTypeAliasDeclaration(node.parent) && !(getObjectFlags(getDeclaredTypeOfSymbol(symbol)) & (ObjectFlags.Anonymous | ObjectFlags.Mapped))) { error(node, Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types); } else if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) { diff --git a/tests/baselines/reference/varianceReferences.errors.txt b/tests/baselines/reference/varianceReferences.errors.txt index 25d23697fba79..4a325de37b397 100644 --- a/tests/baselines/reference/varianceReferences.errors.txt +++ b/tests/baselines/reference/varianceReferences.errors.txt @@ -1,9 +1,23 @@ varianceReferences.ts(3,32): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. -varianceReferences.ts(8,28): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. -varianceReferences.ts(14,32): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. +varianceReferences.ts(9,1): error TS2322: Type '1 | 2' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +varianceReferences.ts(14,28): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. +varianceReferences.ts(19,1): error TS2322: Type '1 | 2' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +varianceReferences.ts(26,32): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. +varianceReferences.ts(31,1): error TS2322: Type '1 | 2' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +varianceReferences.ts(38,20): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. +varianceReferences.ts(43,1): error TS2322: Type 'VarianceShape<1 | 2>' is not assignable to type 'VarianceShape<1>'. + Type '1 | 2' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +varianceReferences.ts(53,24): error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. +varianceReferences.ts(58,1): error TS2322: Type 'VarianceDeepShape<1 | 2>' is not assignable to type 'VarianceDeepShape<1>'. + Type '1 | 2' is not assignable to type '1'. + Type '2' is not assignable to type '1'. -==== varianceReferences.ts (3 errors) ==== +==== varianceReferences.ts (10 errors) ==== type NumericConstraint = Value; type VarianceConstrainedNumber = @@ -11,12 +25,30 @@ varianceReferences.ts(14,32): error TS2637: Variance annotations are only suppor !!! error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. NumericConstraint; + declare let vcn1: VarianceConstrainedNumber<1>; + declare let vcn12: VarianceConstrainedNumber<1 | 2>; + + vcn1 = vcn12; + ~~~~ +!!! error TS2322: Type '1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + vcn12 = vcn1; + type Unconstrained = Value; type VarianceUnconstrained = Unconstrained; ~~~~~~~~~~~~ !!! error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. + declare let vu1: VarianceUnconstrained<1>; + declare let vu12: VarianceUnconstrained<1 | 2>; + + vu1 = vu12; + ~~~ +!!! error TS2322: Type '1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + vu12 = vu1; + type Level3of3Unconstrained = Value; type Level2of3Unconstrained = Level3of3Unconstrained; type Level1of3Unconstrained = Level2of3Unconstrained; @@ -25,11 +57,32 @@ varianceReferences.ts(14,32): error TS2637: Variance annotations are only suppor ~~~~~~~~~~~~ !!! error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. + declare let vdu1: VarianceDeepUnconstrained<1>; + declare let vdu12: VarianceDeepUnconstrained<1 | 2>; + + vdu1 = vdu12; + ~~~~ +!!! error TS2322: Type '1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + vdu12 = vdu1; + interface Shape { value: Value; } type VarianceShape = Shape; + ~~~~~~~~~~~~ +!!! error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. + + declare let vs1: VarianceShape<1>; + declare let vs12: VarianceShape<1 | 2>; + + vs1 = vs12; + ~~~ +!!! error TS2322: Type 'VarianceShape<1 | 2>' is not assignable to type 'VarianceShape<1>'. +!!! error TS2322: Type '1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + vs12 = vs1; interface Level3of3Shape { value: Value; @@ -39,4 +92,16 @@ varianceReferences.ts(14,32): error TS2637: Variance annotations are only suppor type Level1of3Shape = Level2of3Shape; type VarianceDeepShape = Level1of3Shape; + ~~~~~~~~~~~~ +!!! error TS2637: Variance annotations are only supported in type aliases for object, function, constructor, and mapped types. + + declare let vds1: VarianceDeepShape<1>; + declare let vds12: VarianceDeepShape<1 | 2>; + + vds1 = vds12; + ~~~~ +!!! error TS2322: Type 'VarianceDeepShape<1 | 2>' is not assignable to type 'VarianceDeepShape<1>'. +!!! error TS2322: Type '1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + vds12 = vds1; \ No newline at end of file diff --git a/tests/baselines/reference/varianceReferences.js b/tests/baselines/reference/varianceReferences.js deleted file mode 100644 index 12d717da01a50..0000000000000 --- a/tests/baselines/reference/varianceReferences.js +++ /dev/null @@ -1,35 +0,0 @@ -//// [tests/cases/compiler/varianceReferences.ts] //// - -//// [varianceReferences.ts] -type NumericConstraint = Value; - -type VarianceConstrainedNumber = - NumericConstraint; - -type Unconstrained = Value; - -type VarianceUnconstrained = Unconstrained; - -type Level3of3Unconstrained = Value; -type Level2of3Unconstrained = Level3of3Unconstrained; -type Level1of3Unconstrained = Level2of3Unconstrained; - -type VarianceDeepUnconstrained = Level1of3Unconstrained; - -interface Shape { - value: Value; -} - -type VarianceShape = Shape; - -interface Level3of3Shape { - value: Value; -} - -type Level2of3Shape = Level3of3Shape; -type Level1of3Shape = Level2of3Shape; - -type VarianceDeepShape = Level1of3Shape; - - -//// [varianceReferences.js] diff --git a/tests/baselines/reference/varianceReferences.symbols b/tests/baselines/reference/varianceReferences.symbols index 275f3193bf3cc..17c24383bb600 100644 --- a/tests/baselines/reference/varianceReferences.symbols +++ b/tests/baselines/reference/varianceReferences.symbols @@ -14,79 +14,159 @@ type VarianceConstrainedNumber = >NumericConstraint : Symbol(NumericConstraint, Decl(varianceReferences.ts, 0, 0)) >Value : Symbol(Value, Decl(varianceReferences.ts, 2, 31)) +declare let vcn1: VarianceConstrainedNumber<1>; +>vcn1 : Symbol(vcn1, Decl(varianceReferences.ts, 5, 11)) +>VarianceConstrainedNumber : Symbol(VarianceConstrainedNumber, Decl(varianceReferences.ts, 0, 53)) + +declare let vcn12: VarianceConstrainedNumber<1 | 2>; +>vcn12 : Symbol(vcn12, Decl(varianceReferences.ts, 6, 11)) +>VarianceConstrainedNumber : Symbol(VarianceConstrainedNumber, Decl(varianceReferences.ts, 0, 53)) + +vcn1 = vcn12; +>vcn1 : Symbol(vcn1, Decl(varianceReferences.ts, 5, 11)) +>vcn12 : Symbol(vcn12, Decl(varianceReferences.ts, 6, 11)) + +vcn12 = vcn1; +>vcn12 : Symbol(vcn12, Decl(varianceReferences.ts, 6, 11)) +>vcn1 : Symbol(vcn1, Decl(varianceReferences.ts, 5, 11)) + type Unconstrained = Value; ->Unconstrained : Symbol(Unconstrained, Decl(varianceReferences.ts, 3, 27)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 5, 19)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 5, 19)) +>Unconstrained : Symbol(Unconstrained, Decl(varianceReferences.ts, 9, 13)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 11, 19)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 11, 19)) type VarianceUnconstrained = Unconstrained; ->VarianceUnconstrained : Symbol(VarianceUnconstrained, Decl(varianceReferences.ts, 5, 34)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 7, 27)) ->Unconstrained : Symbol(Unconstrained, Decl(varianceReferences.ts, 3, 27)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 7, 27)) +>VarianceUnconstrained : Symbol(VarianceUnconstrained, Decl(varianceReferences.ts, 11, 34)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 13, 27)) +>Unconstrained : Symbol(Unconstrained, Decl(varianceReferences.ts, 9, 13)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 13, 27)) + +declare let vu1: VarianceUnconstrained<1>; +>vu1 : Symbol(vu1, Decl(varianceReferences.ts, 15, 11)) +>VarianceUnconstrained : Symbol(VarianceUnconstrained, Decl(varianceReferences.ts, 11, 34)) + +declare let vu12: VarianceUnconstrained<1 | 2>; +>vu12 : Symbol(vu12, Decl(varianceReferences.ts, 16, 11)) +>VarianceUnconstrained : Symbol(VarianceUnconstrained, Decl(varianceReferences.ts, 11, 34)) + +vu1 = vu12; +>vu1 : Symbol(vu1, Decl(varianceReferences.ts, 15, 11)) +>vu12 : Symbol(vu12, Decl(varianceReferences.ts, 16, 11)) + +vu12 = vu1; +>vu12 : Symbol(vu12, Decl(varianceReferences.ts, 16, 11)) +>vu1 : Symbol(vu1, Decl(varianceReferences.ts, 15, 11)) type Level3of3Unconstrained = Value; ->Level3of3Unconstrained : Symbol(Level3of3Unconstrained, Decl(varianceReferences.ts, 7, 64)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 9, 28)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 9, 28)) +>Level3of3Unconstrained : Symbol(Level3of3Unconstrained, Decl(varianceReferences.ts, 19, 11)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 21, 28)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 21, 28)) type Level2of3Unconstrained = Level3of3Unconstrained; ->Level2of3Unconstrained : Symbol(Level2of3Unconstrained, Decl(varianceReferences.ts, 9, 43)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 10, 28)) ->Level3of3Unconstrained : Symbol(Level3of3Unconstrained, Decl(varianceReferences.ts, 7, 64)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 10, 28)) +>Level2of3Unconstrained : Symbol(Level2of3Unconstrained, Decl(varianceReferences.ts, 21, 43)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 22, 28)) +>Level3of3Unconstrained : Symbol(Level3of3Unconstrained, Decl(varianceReferences.ts, 19, 11)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 22, 28)) type Level1of3Unconstrained = Level2of3Unconstrained; ->Level1of3Unconstrained : Symbol(Level1of3Unconstrained, Decl(varianceReferences.ts, 10, 67)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 11, 28)) ->Level2of3Unconstrained : Symbol(Level2of3Unconstrained, Decl(varianceReferences.ts, 9, 43)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 11, 28)) +>Level1of3Unconstrained : Symbol(Level1of3Unconstrained, Decl(varianceReferences.ts, 22, 67)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 23, 28)) +>Level2of3Unconstrained : Symbol(Level2of3Unconstrained, Decl(varianceReferences.ts, 21, 43)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 23, 28)) type VarianceDeepUnconstrained = Level1of3Unconstrained; ->VarianceDeepUnconstrained : Symbol(VarianceDeepUnconstrained, Decl(varianceReferences.ts, 11, 67)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 13, 31)) ->Level1of3Unconstrained : Symbol(Level1of3Unconstrained, Decl(varianceReferences.ts, 10, 67)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 13, 31)) +>VarianceDeepUnconstrained : Symbol(VarianceDeepUnconstrained, Decl(varianceReferences.ts, 23, 67)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 25, 31)) +>Level1of3Unconstrained : Symbol(Level1of3Unconstrained, Decl(varianceReferences.ts, 22, 67)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 25, 31)) + +declare let vdu1: VarianceDeepUnconstrained<1>; +>vdu1 : Symbol(vdu1, Decl(varianceReferences.ts, 27, 11)) +>VarianceDeepUnconstrained : Symbol(VarianceDeepUnconstrained, Decl(varianceReferences.ts, 23, 67)) + +declare let vdu12: VarianceDeepUnconstrained<1 | 2>; +>vdu12 : Symbol(vdu12, Decl(varianceReferences.ts, 28, 11)) +>VarianceDeepUnconstrained : Symbol(VarianceDeepUnconstrained, Decl(varianceReferences.ts, 23, 67)) + +vdu1 = vdu12; +>vdu1 : Symbol(vdu1, Decl(varianceReferences.ts, 27, 11)) +>vdu12 : Symbol(vdu12, Decl(varianceReferences.ts, 28, 11)) + +vdu12 = vdu1; +>vdu12 : Symbol(vdu12, Decl(varianceReferences.ts, 28, 11)) +>vdu1 : Symbol(vdu1, Decl(varianceReferences.ts, 27, 11)) interface Shape { ->Shape : Symbol(Shape, Decl(varianceReferences.ts, 13, 77)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 15, 16)) +>Shape : Symbol(Shape, Decl(varianceReferences.ts, 31, 13)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 33, 16)) value: Value; ->value : Symbol(Shape.value, Decl(varianceReferences.ts, 15, 24)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 15, 16)) +>value : Symbol(Shape.value, Decl(varianceReferences.ts, 33, 24)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 33, 16)) } type VarianceShape = Shape; ->VarianceShape : Symbol(VarianceShape, Decl(varianceReferences.ts, 17, 1)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 19, 19)) ->Shape : Symbol(Shape, Decl(varianceReferences.ts, 13, 77)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 19, 19)) +>VarianceShape : Symbol(VarianceShape, Decl(varianceReferences.ts, 35, 1)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 37, 19)) +>Shape : Symbol(Shape, Decl(varianceReferences.ts, 31, 13)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 37, 19)) + +declare let vs1: VarianceShape<1>; +>vs1 : Symbol(vs1, Decl(varianceReferences.ts, 39, 11)) +>VarianceShape : Symbol(VarianceShape, Decl(varianceReferences.ts, 35, 1)) + +declare let vs12: VarianceShape<1 | 2>; +>vs12 : Symbol(vs12, Decl(varianceReferences.ts, 40, 11)) +>VarianceShape : Symbol(VarianceShape, Decl(varianceReferences.ts, 35, 1)) + +vs1 = vs12; +>vs1 : Symbol(vs1, Decl(varianceReferences.ts, 39, 11)) +>vs12 : Symbol(vs12, Decl(varianceReferences.ts, 40, 11)) + +vs12 = vs1; +>vs12 : Symbol(vs12, Decl(varianceReferences.ts, 40, 11)) +>vs1 : Symbol(vs1, Decl(varianceReferences.ts, 39, 11)) interface Level3of3Shape { ->Level3of3Shape : Symbol(Level3of3Shape, Decl(varianceReferences.ts, 19, 48)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 21, 25)) +>Level3of3Shape : Symbol(Level3of3Shape, Decl(varianceReferences.ts, 43, 11)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 45, 25)) value: Value; ->value : Symbol(Level3of3Shape.value, Decl(varianceReferences.ts, 21, 33)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 21, 25)) +>value : Symbol(Level3of3Shape.value, Decl(varianceReferences.ts, 45, 33)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 45, 25)) } type Level2of3Shape = Level3of3Shape; ->Level2of3Shape : Symbol(Level2of3Shape, Decl(varianceReferences.ts, 23, 1)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 25, 20)) ->Level3of3Shape : Symbol(Level3of3Shape, Decl(varianceReferences.ts, 19, 48)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 25, 20)) +>Level2of3Shape : Symbol(Level2of3Shape, Decl(varianceReferences.ts, 47, 1)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 49, 20)) +>Level3of3Shape : Symbol(Level3of3Shape, Decl(varianceReferences.ts, 43, 11)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 49, 20)) type Level1of3Shape = Level2of3Shape; ->Level1of3Shape : Symbol(Level1of3Shape, Decl(varianceReferences.ts, 25, 51)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 26, 20)) ->Level2of3Shape : Symbol(Level2of3Shape, Decl(varianceReferences.ts, 23, 1)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 26, 20)) +>Level1of3Shape : Symbol(Level1of3Shape, Decl(varianceReferences.ts, 49, 51)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 50, 20)) +>Level2of3Shape : Symbol(Level2of3Shape, Decl(varianceReferences.ts, 47, 1)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 50, 20)) type VarianceDeepShape = Level1of3Shape; ->VarianceDeepShape : Symbol(VarianceDeepShape, Decl(varianceReferences.ts, 26, 51)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 28, 23)) ->Level1of3Shape : Symbol(Level1of3Shape, Decl(varianceReferences.ts, 25, 51)) ->Value : Symbol(Value, Decl(varianceReferences.ts, 28, 23)) +>VarianceDeepShape : Symbol(VarianceDeepShape, Decl(varianceReferences.ts, 50, 51)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 52, 23)) +>Level1of3Shape : Symbol(Level1of3Shape, Decl(varianceReferences.ts, 49, 51)) +>Value : Symbol(Value, Decl(varianceReferences.ts, 52, 23)) + +declare let vds1: VarianceDeepShape<1>; +>vds1 : Symbol(vds1, Decl(varianceReferences.ts, 54, 11)) +>VarianceDeepShape : Symbol(VarianceDeepShape, Decl(varianceReferences.ts, 50, 51)) + +declare let vds12: VarianceDeepShape<1 | 2>; +>vds12 : Symbol(vds12, Decl(varianceReferences.ts, 55, 11)) +>VarianceDeepShape : Symbol(VarianceDeepShape, Decl(varianceReferences.ts, 50, 51)) + +vds1 = vds12; +>vds1 : Symbol(vds1, Decl(varianceReferences.ts, 54, 11)) +>vds12 : Symbol(vds12, Decl(varianceReferences.ts, 55, 11)) + +vds12 = vds1; +>vds12 : Symbol(vds12, Decl(varianceReferences.ts, 55, 11)) +>vds1 : Symbol(vds1, Decl(varianceReferences.ts, 54, 11)) diff --git a/tests/baselines/reference/varianceReferences.types b/tests/baselines/reference/varianceReferences.types index 51b803f94fbc2..8094ed685b449 100644 --- a/tests/baselines/reference/varianceReferences.types +++ b/tests/baselines/reference/varianceReferences.types @@ -11,6 +11,30 @@ type VarianceConstrainedNumber = NumericConstraint; +declare let vcn1: VarianceConstrainedNumber<1>; +>vcn1 : 1 +> : ^ + +declare let vcn12: VarianceConstrainedNumber<1 | 2>; +>vcn12 : 1 | 2 +> : ^^^^^ + +vcn1 = vcn12; +>vcn1 = vcn12 : 1 | 2 +> : ^^^^^ +>vcn1 : 1 +> : ^ +>vcn12 : 1 | 2 +> : ^^^^^ + +vcn12 = vcn1; +>vcn12 = vcn1 : 1 +> : ^ +>vcn12 : 1 | 2 +> : ^^^^^ +>vcn1 : 1 +> : ^ + type Unconstrained = Value; >Unconstrained : Value > : ^^^^^ @@ -19,6 +43,30 @@ type VarianceUnconstrained = Unconstrained; >VarianceUnconstrained : Value > : ^^^^^ +declare let vu1: VarianceUnconstrained<1>; +>vu1 : 1 +> : ^ + +declare let vu12: VarianceUnconstrained<1 | 2>; +>vu12 : 1 | 2 +> : ^^^^^ + +vu1 = vu12; +>vu1 = vu12 : 1 | 2 +> : ^^^^^ +>vu1 : 1 +> : ^ +>vu12 : 1 | 2 +> : ^^^^^ + +vu12 = vu1; +>vu12 = vu1 : 1 +> : ^ +>vu12 : 1 | 2 +> : ^^^^^ +>vu1 : 1 +> : ^ + type Level3of3Unconstrained = Value; >Level3of3Unconstrained : Value > : ^^^^^ @@ -35,6 +83,30 @@ type VarianceDeepUnconstrained = Level1of3Unconstrained; >VarianceDeepUnconstrained : Value > : ^^^^^ +declare let vdu1: VarianceDeepUnconstrained<1>; +>vdu1 : 1 +> : ^ + +declare let vdu12: VarianceDeepUnconstrained<1 | 2>; +>vdu12 : 1 | 2 +> : ^^^^^ + +vdu1 = vdu12; +>vdu1 = vdu12 : 1 | 2 +> : ^^^^^ +>vdu1 : 1 +> : ^ +>vdu12 : 1 | 2 +> : ^^^^^ + +vdu12 = vdu1; +>vdu12 = vdu1 : 1 +> : ^ +>vdu12 : 1 | 2 +> : ^^^^^ +>vdu1 : 1 +> : ^ + interface Shape { value: Value; >value : Value @@ -45,6 +117,30 @@ type VarianceShape = Shape; >VarianceShape : VarianceShape > : ^^^^^^^^^^^^^^^^^^^^ +declare let vs1: VarianceShape<1>; +>vs1 : VarianceShape<1> +> : ^^^^^^^^^^^^^^^^ + +declare let vs12: VarianceShape<1 | 2>; +>vs12 : VarianceShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^ + +vs1 = vs12; +>vs1 = vs12 : VarianceShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^ +>vs1 : VarianceShape<1> +> : ^^^^^^^^^^^^^^^^ +>vs12 : VarianceShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^ + +vs12 = vs1; +>vs12 = vs1 : VarianceShape<1> +> : ^^^^^^^^^^^^^^^^ +>vs12 : VarianceShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^ +>vs1 : VarianceShape<1> +> : ^^^^^^^^^^^^^^^^ + interface Level3of3Shape { value: Value; >value : Value @@ -63,3 +159,27 @@ type VarianceDeepShape = Level1of3Shape; >VarianceDeepShape : VarianceDeepShape > : ^^^^^^^^^^^^^^^^^^^^^^^^ +declare let vds1: VarianceDeepShape<1>; +>vds1 : VarianceDeepShape<1> +> : ^^^^^^^^^^^^^^^^^^^^ + +declare let vds12: VarianceDeepShape<1 | 2>; +>vds12 : VarianceDeepShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + +vds1 = vds12; +>vds1 = vds12 : VarianceDeepShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>vds1 : VarianceDeepShape<1> +> : ^^^^^^^^^^^^^^^^^^^^ +>vds12 : VarianceDeepShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^^^^^ + +vds12 = vds1; +>vds12 = vds1 : VarianceDeepShape<1> +> : ^^^^^^^^^^^^^^^^^^^^ +>vds12 : VarianceDeepShape<1 | 2> +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>vds1 : VarianceDeepShape<1> +> : ^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/cases/compiler/varianceReferences.ts b/tests/cases/compiler/varianceReferences.ts index a31f34df33206..36ab61a86d732 100644 --- a/tests/cases/compiler/varianceReferences.ts +++ b/tests/cases/compiler/varianceReferences.ts @@ -1,24 +1,51 @@ +// @strict: true +// @noEmit: true + type NumericConstraint = Value; type VarianceConstrainedNumber = NumericConstraint; +declare let vcn1: VarianceConstrainedNumber<1>; +declare let vcn12: VarianceConstrainedNumber<1 | 2>; + +vcn1 = vcn12; +vcn12 = vcn1; + type Unconstrained = Value; type VarianceUnconstrained = Unconstrained; +declare let vu1: VarianceUnconstrained<1>; +declare let vu12: VarianceUnconstrained<1 | 2>; + +vu1 = vu12; +vu12 = vu1; + type Level3of3Unconstrained = Value; type Level2of3Unconstrained = Level3of3Unconstrained; type Level1of3Unconstrained = Level2of3Unconstrained; type VarianceDeepUnconstrained = Level1of3Unconstrained; +declare let vdu1: VarianceDeepUnconstrained<1>; +declare let vdu12: VarianceDeepUnconstrained<1 | 2>; + +vdu1 = vdu12; +vdu12 = vdu1; + interface Shape { value: Value; } type VarianceShape = Shape; +declare let vs1: VarianceShape<1>; +declare let vs12: VarianceShape<1 | 2>; + +vs1 = vs12; +vs12 = vs1; + interface Level3of3Shape { value: Value; } @@ -27,3 +54,9 @@ type Level2of3Shape = Level3of3Shape; type Level1of3Shape = Level2of3Shape; type VarianceDeepShape = Level1of3Shape; + +declare let vds1: VarianceDeepShape<1>; +declare let vds12: VarianceDeepShape<1 | 2>; + +vds1 = vds12; +vds12 = vds1;