Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate constraint with default upon comparison (#31240)
- Loading branch information
Showing
5 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...baselines/reference/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//// [typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts] | ||
// tricky interface | ||
interface Settable<T, V> { | ||
set(value: V): T; | ||
} | ||
|
||
// implement | ||
class Identity<V> implements Settable<Identity<V>, V> { | ||
readonly item: V; | ||
constructor(value: V) { | ||
this.item = value; | ||
} | ||
public set(value: V): Identity<V> { | ||
return new Identity<V>(value); | ||
} | ||
} | ||
|
||
// generic parameter default | ||
interface Test1<V, T extends Settable<T, V> = Identity<V>> { }; | ||
let test1: Test1<number>; | ||
|
||
// not generic parameter default | ||
interface Test2Base<V, T extends Settable<T, V>> { }; | ||
type Test2<V> = Test2Base<V, Identity<V>>; | ||
let test2: Test2<number>; | ||
|
||
|
||
//// [typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.js] | ||
// implement | ||
var Identity = /** @class */ (function () { | ||
function Identity(value) { | ||
this.item = value; | ||
} | ||
Identity.prototype.set = function (value) { | ||
return new Identity(value); | ||
}; | ||
return Identity; | ||
}()); | ||
; | ||
var test1; | ||
; | ||
var test2; |
87 changes: 87 additions & 0 deletions
87
...ines/reference/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
=== tests/cases/compiler/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts === | ||
// tricky interface | ||
interface Settable<T, V> { | ||
>Settable : Symbol(Settable, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 0, 0)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 1, 19)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 1, 21)) | ||
|
||
set(value: V): T; | ||
>set : Symbol(Settable.set, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 1, 26)) | ||
>value : Symbol(value, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 2, 8)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 1, 21)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 1, 19)) | ||
} | ||
|
||
// implement | ||
class Identity<V> implements Settable<Identity<V>, V> { | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
>Settable : Symbol(Settable, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 0, 0)) | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
|
||
readonly item: V; | ||
>item : Symbol(Identity.item, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 55)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
|
||
constructor(value: V) { | ||
>value : Symbol(value, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 8, 16)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
|
||
this.item = value; | ||
>this.item : Symbol(Identity.item, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 55)) | ||
>this : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>item : Symbol(Identity.item, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 55)) | ||
>value : Symbol(value, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 8, 16)) | ||
} | ||
public set(value: V): Identity<V> { | ||
>set : Symbol(Identity.set, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 10, 5)) | ||
>value : Symbol(value, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 11, 15)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
|
||
return new Identity<V>(value); | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 6, 15)) | ||
>value : Symbol(value, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 11, 15)) | ||
} | ||
} | ||
|
||
// generic parameter default | ||
interface Test1<V, T extends Settable<T, V> = Identity<V>> { }; | ||
>Test1 : Symbol(Test1, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 14, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 17, 16)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 17, 18)) | ||
>Settable : Symbol(Settable, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 0, 0)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 17, 18)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 17, 16)) | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 17, 16)) | ||
|
||
let test1: Test1<number>; | ||
>test1 : Symbol(test1, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 18, 3)) | ||
>Test1 : Symbol(Test1, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 14, 1)) | ||
|
||
// not generic parameter default | ||
interface Test2Base<V, T extends Settable<T, V>> { }; | ||
>Test2Base : Symbol(Test2Base, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 18, 25)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 20)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 22)) | ||
>Settable : Symbol(Settable, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 0, 0)) | ||
>T : Symbol(T, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 22)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 20)) | ||
|
||
type Test2<V> = Test2Base<V, Identity<V>>; | ||
>Test2 : Symbol(Test2, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 53)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 22, 11)) | ||
>Test2Base : Symbol(Test2Base, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 18, 25)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 22, 11)) | ||
>Identity : Symbol(Identity, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 3, 1)) | ||
>V : Symbol(V, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 22, 11)) | ||
|
||
let test2: Test2<number>; | ||
>test2 : Symbol(test2, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 23, 3)) | ||
>Test2 : Symbol(Test2, Decl(typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts, 21, 53)) | ||
|
49 changes: 49 additions & 0 deletions
49
...elines/reference/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
=== tests/cases/compiler/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts === | ||
// tricky interface | ||
interface Settable<T, V> { | ||
set(value: V): T; | ||
>set : (value: V) => T | ||
>value : V | ||
} | ||
|
||
// implement | ||
class Identity<V> implements Settable<Identity<V>, V> { | ||
>Identity : Identity<V> | ||
|
||
readonly item: V; | ||
>item : V | ||
|
||
constructor(value: V) { | ||
>value : V | ||
|
||
this.item = value; | ||
>this.item = value : V | ||
>this.item : V | ||
>this : this | ||
>item : V | ||
>value : V | ||
} | ||
public set(value: V): Identity<V> { | ||
>set : (value: V) => Identity<V> | ||
>value : V | ||
|
||
return new Identity<V>(value); | ||
>new Identity<V>(value) : Identity<V> | ||
>Identity : typeof Identity | ||
>value : V | ||
} | ||
} | ||
|
||
// generic parameter default | ||
interface Test1<V, T extends Settable<T, V> = Identity<V>> { }; | ||
let test1: Test1<number>; | ||
>test1 : Test1<number, Identity<number>> | ||
|
||
// not generic parameter default | ||
interface Test2Base<V, T extends Settable<T, V>> { }; | ||
type Test2<V> = Test2Base<V, Identity<V>>; | ||
>Test2 : Test2Base<V, Identity<V>> | ||
|
||
let test2: Test2<number>; | ||
>test2 : Test2Base<number, Identity<number>> | ||
|
24 changes: 24 additions & 0 deletions
24
tests/cases/compiler/typePartameterConstraintInstantiatedWithDefaultWhenCheckingDefault.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// tricky interface | ||
interface Settable<T, V> { | ||
set(value: V): T; | ||
} | ||
|
||
// implement | ||
class Identity<V> implements Settable<Identity<V>, V> { | ||
readonly item: V; | ||
constructor(value: V) { | ||
this.item = value; | ||
} | ||
public set(value: V): Identity<V> { | ||
return new Identity<V>(value); | ||
} | ||
} | ||
|
||
// generic parameter default | ||
interface Test1<V, T extends Settable<T, V> = Identity<V>> { }; | ||
let test1: Test1<number>; | ||
|
||
// not generic parameter default | ||
interface Test2Base<V, T extends Settable<T, V>> { }; | ||
type Test2<V> = Test2Base<V, Identity<V>>; | ||
let test2: Test2<number>; |