Skip to content

Commit e4235a7

Browse files
committed
Contravariant and bivariant default to never, else use constraint
1 parent 061e41a commit e4235a7

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/compiler/checker.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10150,10 +10150,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1015010150
}
1015110151
const variance = variances[i];
1015210152
switch (variance & VarianceFlags.VarianceMask) {
10153-
case VarianceFlags.Independent:
10154-
case VarianceFlags.Bivariant:
10155-
return anyType;
1015610153
case VarianceFlags.Contravariant:
10154+
case VarianceFlags.Bivariant:
1015710155
return neverType;
1015810156
}
1015910157
return getBaseConstraintOfType(typeParameter) || unknownType;

tests/baselines/reference/accessorsOverrideProperty9.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function ApiItemContainerMixin<TBaseClass extends IApiItemConstructor>(
6868
}
6969

7070
return MixedClass;
71-
>MixedClass : ((abstract new (...args: any[]) => MixedClass) & { prototype: ApiItemContainerMixin<any>.MixedClass; }) & TBaseClass
71+
>MixedClass : ((abstract new (...args: any[]) => MixedClass) & { prototype: ApiItemContainerMixin<IApiItemConstructor>.MixedClass; }) & TBaseClass
7272
}
7373

7474
// Subclass inheriting from mixin

tests/baselines/reference/instantiationExpressions.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ function f3() {
9898
>f3 : () => void
9999

100100
let c1 = C<string>; // { new (x: string): C<string>; f<U>(x: U): T[]; prototype: C<unknown>; }
101-
>c1 : { new (x: string): C<string>; prototype: C<any>; f<U>(x: U): U[]; }
102-
>C<string> : { new (x: string): C<string>; prototype: C<any>; f<U>(x: U): U[]; }
101+
>c1 : { new (x: string): C<string>; prototype: C<unknown>; f<U>(x: U): U[]; }
102+
>C<string> : { new (x: string): C<string>; prototype: C<unknown>; f<U>(x: U): U[]; }
103103
>C : typeof C
104104

105105
let f1 = C.f<string>; // (x: string) => string[]

tests/baselines/reference/overrideBaseIntersectionMethod.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Constructor<T> = new (...args: any[]) => T;
66
>args : any[]
77

88
const WithLocation = <T extends Constructor<Point>>(Base: T) => class extends Base {
9-
>WithLocation : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T
10-
><T extends Constructor<Point>>(Base: T) => class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T
9+
>WithLocation : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<Constructor<Point>>.(Anonymous class); } & T
10+
><T extends Constructor<Point>>(Base: T) => class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<Constructor<Point>>.(Anonymous class); } & T
1111
>Base : T
12-
>class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : { new (...args: any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T
12+
>class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : { new (...args: any[]): (Anonymous class); prototype: WithLocation<Constructor<Point>>.(Anonymous class); } & T
1313
>Base : Point
1414

1515
getLocation(): [number, number] {
@@ -58,7 +58,7 @@ class Point {
5858
class Foo extends WithLocation(Point) {
5959
>Foo : Foo
6060
>WithLocation(Point) : WithLocation<typeof Point>.(Anonymous class) & Point
61-
>WithLocation : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T
61+
>WithLocation : <T extends Constructor<Point>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithLocation<Constructor<Point>>.(Anonymous class); } & T
6262
>Point : typeof Point
6363

6464
calculate() {

0 commit comments

Comments
 (0)