Skip to content

Commit

Permalink
Add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Apr 11, 2022
1 parent 5b20a2f commit 838393e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/baselines/reference/varianceAnnotations.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,18 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/varianceAnnotati
!!! error TS2345: Types of property '_storedEvent' are incompatible.
!!! error TS2345: Type '{ type: "PLAY"; value: number; } | { type: "RESET"; }' is not assignable to type '{ type: "PLAY"; value: number; }'.
!!! error TS2345: Type '{ type: "RESET"; }' is not assignable to type '{ type: "PLAY"; value: number; }'.

// Repros from #48618

let Anon = class <out T> {
foo(): InstanceType<(typeof Anon<T>)> {
return this;
}
}

let OuterC = class C<out T> {
foo(): C<T> {
return this;
}
}

41 changes: 41 additions & 0 deletions tests/baselines/reference/varianceAnnotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ interpret(machine);
declare const qq: ActionObject<{ type: "PLAY"; value: number }>;

createMachine<{ type: "PLAY"; value: number } | { type: "RESET" }>(qq); // Error

// Repros from #48618

let Anon = class <out T> {
foo(): InstanceType<(typeof Anon<T>)> {
return this;
}
}

let OuterC = class C<out T> {
foo(): C<T> {
return this;
}
}


//// [varianceAnnotations.js]
Expand Down Expand Up @@ -186,6 +200,23 @@ var notString = pu; // Error
var machine = createMachine({});
interpret(machine);
createMachine(qq); // Error
// Repros from #48618
var Anon = /** @class */ (function () {
function class_1() {
}
class_1.prototype.foo = function () {
return this;
};
return class_1;
}());
var OuterC = /** @class */ (function () {
function C() {
}
C.prototype.foo = function () {
return this;
};
return C;
}());


//// [varianceAnnotations.d.ts]
Expand Down Expand Up @@ -293,3 +324,13 @@ declare const qq: ActionObject<{
type: "PLAY";
value: number;
}>;
declare let Anon: {
new <out T>(): {
foo(): any;
};
};
declare let OuterC: {
new <out T>(): {
foo(): any;
};
};
32 changes: 32 additions & 0 deletions tests/baselines/reference/varianceAnnotations.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,35 @@ createMachine<{ type: "PLAY"; value: number } | { type: "RESET" }>(qq); // Erro
>type : Symbol(type, Decl(varianceAnnotations.ts, 159, 49))
>qq : Symbol(qq, Decl(varianceAnnotations.ts, 157, 13))

// Repros from #48618

let Anon = class <out T> {
>Anon : Symbol(Anon, Decl(varianceAnnotations.ts, 163, 3))
>T : Symbol(T, Decl(varianceAnnotations.ts, 163, 18))

foo(): InstanceType<(typeof Anon<T>)> {
>foo : Symbol(Anon.foo, Decl(varianceAnnotations.ts, 163, 26))
>InstanceType : Symbol(InstanceType, Decl(lib.es5.d.ts, --, --))
>Anon : Symbol(Anon, Decl(varianceAnnotations.ts, 163, 3))
>T : Symbol(T, Decl(varianceAnnotations.ts, 163, 18))

return this;
>this : Symbol(Anon, Decl(varianceAnnotations.ts, 163, 10))
}
}

let OuterC = class C<out T> {
>OuterC : Symbol(OuterC, Decl(varianceAnnotations.ts, 169, 3))
>C : Symbol(C, Decl(varianceAnnotations.ts, 169, 12))
>T : Symbol(T, Decl(varianceAnnotations.ts, 169, 21))

foo(): C<T> {
>foo : Symbol(C.foo, Decl(varianceAnnotations.ts, 169, 29))
>C : Symbol(C, Decl(varianceAnnotations.ts, 169, 12))
>T : Symbol(T, Decl(varianceAnnotations.ts, 169, 21))

return this;
>this : Symbol(C, Decl(varianceAnnotations.ts, 169, 12))
}
}

28 changes: 28 additions & 0 deletions tests/baselines/reference/varianceAnnotations.types
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,31 @@ createMachine<{ type: "PLAY"; value: number } | { type: "RESET" }>(qq); // Erro
>type : "RESET"
>qq : ActionObject<{ type: "PLAY"; value: number; }>

// Repros from #48618

let Anon = class <out T> {
>Anon : typeof Anon
>class <out T> { foo(): InstanceType<(typeof Anon<T>)> { return this; }} : typeof Anon

foo(): InstanceType<(typeof Anon<T>)> {
>foo : () => InstanceType<(typeof Anon<T>)>
>Anon : typeof Anon

return this;
>this : this
}
}

let OuterC = class C<out T> {
>OuterC : typeof C
>class C<out T> { foo(): C<T> { return this; }} : typeof C
>C : typeof C

foo(): C<T> {
>foo : () => C<T>

return this;
>this : this
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ interpret(machine);
declare const qq: ActionObject<{ type: "PLAY"; value: number }>;

createMachine<{ type: "PLAY"; value: number } | { type: "RESET" }>(qq); // Error

// Repros from #48618

let Anon = class <out T> {
foo(): InstanceType<(typeof Anon<T>)> {
return this;
}
}

let OuterC = class C<out T> {
foo(): C<T> {
return this;
}
}

0 comments on commit 838393e

Please sign in to comment.