Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/baselines/reference/variance.js
Original file line number Diff line number Diff line change
@@ -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 changes: 62 additions & 0 deletions tests/baselines/reference/variance.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 58 additions & 0 deletions tests/baselines/reference/variance.types
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions tests/cases/conformance/types/conditional/variance.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}