mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 10:58:20 -05:00
Add regressions for conditional types that affect parameter variance (#30146)
This commit is contained in:
committed by
Wesley Wigham
parent
e383b0d4f7
commit
5bef1aa13c
45
tests/baselines/reference/variance.js
Normal file
45
tests/baselines/reference/variance.js
Normal file
@@ -0,0 +1,45 @@
|
||||
//// [variance.ts]
|
||||
// Test cases for parameter variances affected by conditional types.
|
||||
|
||||
// Repro from #30047
|
||||
|
||||
interface Foo<T> {
|
||||
prop: T extends unknown ? true : false;
|
||||
}
|
||||
|
||||
const foo = { prop: true } as const;
|
||||
const x: Foo<1> = foo;
|
||||
const y: Foo<number> = foo;
|
||||
const z: Foo<number> = x;
|
||||
|
||||
|
||||
// Repro from #30118
|
||||
|
||||
class Bar<T extends string> {
|
||||
private static instance: Bar<string>[];
|
||||
|
||||
cast(_name: ([T] extends [string] ? string : string)) { }
|
||||
|
||||
pushThis() {
|
||||
Bar.instance.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [variance.js]
|
||||
"use strict";
|
||||
// Test cases for parameter variances affected by conditional types.
|
||||
var foo = { prop: true };
|
||||
var x = foo;
|
||||
var y = foo;
|
||||
var z = x;
|
||||
// Repro from #30118
|
||||
var Bar = /** @class */ (function () {
|
||||
function Bar() {
|
||||
}
|
||||
Bar.prototype.cast = function (_name) { };
|
||||
Bar.prototype.pushThis = function () {
|
||||
Bar.instance.push(this);
|
||||
};
|
||||
return Bar;
|
||||
}());
|
||||
62
tests/baselines/reference/variance.symbols
Normal file
62
tests/baselines/reference/variance.symbols
Normal file
@@ -0,0 +1,62 @@
|
||||
=== tests/cases/conformance/types/conditional/variance.ts ===
|
||||
// Test cases for parameter variances affected by conditional types.
|
||||
|
||||
// Repro from #30047
|
||||
|
||||
interface Foo<T> {
|
||||
>Foo : Symbol(Foo, Decl(variance.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(variance.ts, 4, 14))
|
||||
|
||||
prop: T extends unknown ? true : false;
|
||||
>prop : Symbol(Foo.prop, Decl(variance.ts, 4, 18))
|
||||
>T : Symbol(T, Decl(variance.ts, 4, 14))
|
||||
}
|
||||
|
||||
const foo = { prop: true } as const;
|
||||
>foo : Symbol(foo, Decl(variance.ts, 8, 5))
|
||||
>prop : Symbol(prop, Decl(variance.ts, 8, 13))
|
||||
|
||||
const x: Foo<1> = foo;
|
||||
>x : Symbol(x, Decl(variance.ts, 9, 5))
|
||||
>Foo : Symbol(Foo, Decl(variance.ts, 0, 0))
|
||||
>foo : Symbol(foo, Decl(variance.ts, 8, 5))
|
||||
|
||||
const y: Foo<number> = foo;
|
||||
>y : Symbol(y, Decl(variance.ts, 10, 5))
|
||||
>Foo : Symbol(Foo, Decl(variance.ts, 0, 0))
|
||||
>foo : Symbol(foo, Decl(variance.ts, 8, 5))
|
||||
|
||||
const z: Foo<number> = x;
|
||||
>z : Symbol(z, Decl(variance.ts, 11, 5))
|
||||
>Foo : Symbol(Foo, Decl(variance.ts, 0, 0))
|
||||
>x : Symbol(x, Decl(variance.ts, 9, 5))
|
||||
|
||||
|
||||
// Repro from #30118
|
||||
|
||||
class Bar<T extends string> {
|
||||
>Bar : Symbol(Bar, Decl(variance.ts, 11, 25))
|
||||
>T : Symbol(T, Decl(variance.ts, 16, 10))
|
||||
|
||||
private static instance: Bar<string>[];
|
||||
>instance : Symbol(Bar.instance, Decl(variance.ts, 16, 29))
|
||||
>Bar : Symbol(Bar, Decl(variance.ts, 11, 25))
|
||||
|
||||
cast(_name: ([T] extends [string] ? string : string)) { }
|
||||
>cast : Symbol(Bar.cast, Decl(variance.ts, 17, 41))
|
||||
>_name : Symbol(_name, Decl(variance.ts, 19, 7))
|
||||
>T : Symbol(T, Decl(variance.ts, 16, 10))
|
||||
|
||||
pushThis() {
|
||||
>pushThis : Symbol(Bar.pushThis, Decl(variance.ts, 19, 59))
|
||||
|
||||
Bar.instance.push(this);
|
||||
>Bar.instance.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>Bar.instance : Symbol(Bar.instance, Decl(variance.ts, 16, 29))
|
||||
>Bar : Symbol(Bar, Decl(variance.ts, 11, 25))
|
||||
>instance : Symbol(Bar.instance, Decl(variance.ts, 16, 29))
|
||||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
|
||||
>this : Symbol(Bar, Decl(variance.ts, 11, 25))
|
||||
}
|
||||
}
|
||||
|
||||
58
tests/baselines/reference/variance.types
Normal file
58
tests/baselines/reference/variance.types
Normal file
@@ -0,0 +1,58 @@
|
||||
=== tests/cases/conformance/types/conditional/variance.ts ===
|
||||
// Test cases for parameter variances affected by conditional types.
|
||||
|
||||
// Repro from #30047
|
||||
|
||||
interface Foo<T> {
|
||||
prop: T extends unknown ? true : false;
|
||||
>prop : T extends unknown ? true : false
|
||||
>true : true
|
||||
>false : false
|
||||
}
|
||||
|
||||
const foo = { prop: true } as const;
|
||||
>foo : { readonly prop: true; }
|
||||
>{ prop: true } as const : { readonly prop: true; }
|
||||
>{ prop: true } : { readonly prop: true; }
|
||||
>prop : true
|
||||
>true : true
|
||||
|
||||
const x: Foo<1> = foo;
|
||||
>x : Foo<1>
|
||||
>foo : { readonly prop: true; }
|
||||
|
||||
const y: Foo<number> = foo;
|
||||
>y : Foo<number>
|
||||
>foo : { readonly prop: true; }
|
||||
|
||||
const z: Foo<number> = x;
|
||||
>z : Foo<number>
|
||||
>x : Foo<1>
|
||||
|
||||
|
||||
// Repro from #30118
|
||||
|
||||
class Bar<T extends string> {
|
||||
>Bar : Bar<T>
|
||||
|
||||
private static instance: Bar<string>[];
|
||||
>instance : Bar<string>[]
|
||||
|
||||
cast(_name: ([T] extends [string] ? string : string)) { }
|
||||
>cast : (_name: [T] extends [string] ? string : string) => void
|
||||
>_name : [T] extends [string] ? string : string
|
||||
|
||||
pushThis() {
|
||||
>pushThis : () => void
|
||||
|
||||
Bar.instance.push(this);
|
||||
>Bar.instance.push(this) : number
|
||||
>Bar.instance.push : (...items: Bar<string>[]) => number
|
||||
>Bar.instance : Bar<string>[]
|
||||
>Bar : typeof Bar
|
||||
>instance : Bar<string>[]
|
||||
>push : (...items: Bar<string>[]) => number
|
||||
>this : this
|
||||
}
|
||||
}
|
||||
|
||||
27
tests/cases/conformance/types/conditional/variance.ts
Normal file
27
tests/cases/conformance/types/conditional/variance.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// @strict: true
|
||||
|
||||
// Test cases for parameter variances affected by conditional types.
|
||||
|
||||
// Repro from #30047
|
||||
|
||||
interface Foo<T> {
|
||||
prop: T extends unknown ? true : false;
|
||||
}
|
||||
|
||||
const foo = { prop: true } as const;
|
||||
const x: Foo<1> = foo;
|
||||
const y: Foo<number> = foo;
|
||||
const z: Foo<number> = x;
|
||||
|
||||
|
||||
// Repro from #30118
|
||||
|
||||
class Bar<T extends string> {
|
||||
private static instance: Bar<string>[];
|
||||
|
||||
cast(_name: ([T] extends [string] ? string : string)) { }
|
||||
|
||||
pushThis() {
|
||||
Bar.instance.push(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user