Skip to content

Commit 8a85b2a

Browse files
authored
Add test case for intersection/constraint bug fixed in 4.9 (#54972)
1 parent c468960 commit 8a85b2a

4 files changed

+148
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] ////
2+
3+
//// [intersectionSatisfiesConstraint.ts]
4+
interface FirstInterface {
5+
commonProperty: number
6+
}
7+
8+
interface SecondInterface {
9+
commonProperty: number
10+
}
11+
12+
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
13+
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
14+
mySecondFunction(newParam)
15+
}
16+
17+
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
18+
return newParam
19+
}
20+
21+
22+
//// [intersectionSatisfiesConstraint.js]
23+
"use strict";
24+
var myFirstFunction = function (param1) {
25+
var newParam = Object.assign(param1, { otherProperty: 3 });
26+
mySecondFunction(newParam);
27+
};
28+
var mySecondFunction = function (newParam) {
29+
return newParam;
30+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] ////
2+
3+
=== intersectionSatisfiesConstraint.ts ===
4+
interface FirstInterface {
5+
>FirstInterface : Symbol(FirstInterface, Decl(intersectionSatisfiesConstraint.ts, 0, 0))
6+
7+
commonProperty: number
8+
>commonProperty : Symbol(FirstInterface.commonProperty, Decl(intersectionSatisfiesConstraint.ts, 0, 26))
9+
}
10+
11+
interface SecondInterface {
12+
>SecondInterface : Symbol(SecondInterface, Decl(intersectionSatisfiesConstraint.ts, 2, 1))
13+
14+
commonProperty: number
15+
>commonProperty : Symbol(SecondInterface.commonProperty, Decl(intersectionSatisfiesConstraint.ts, 4, 27))
16+
}
17+
18+
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
19+
>myFirstFunction : Symbol(myFirstFunction, Decl(intersectionSatisfiesConstraint.ts, 8, 5))
20+
>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25))
21+
>FirstInterface : Symbol(FirstInterface, Decl(intersectionSatisfiesConstraint.ts, 0, 0))
22+
>SecondInterface : Symbol(SecondInterface, Decl(intersectionSatisfiesConstraint.ts, 2, 1))
23+
>param1 : Symbol(param1, Decl(intersectionSatisfiesConstraint.ts, 8, 69))
24+
>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25))
25+
26+
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
27+
>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9))
28+
>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 8, 25))
29+
>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 25))
30+
>Object.assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
31+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
32+
>assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
33+
>param1 : Symbol(param1, Decl(intersectionSatisfiesConstraint.ts, 8, 69))
34+
>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 9, 75))
35+
36+
mySecondFunction(newParam)
37+
>mySecondFunction : Symbol(mySecondFunction, Decl(intersectionSatisfiesConstraint.ts, 13, 5))
38+
>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 9, 9))
39+
}
40+
41+
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
42+
>mySecondFunction : Symbol(mySecondFunction, Decl(intersectionSatisfiesConstraint.ts, 13, 5))
43+
>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 13, 26))
44+
>commonProperty : Symbol(commonProperty, Decl(intersectionSatisfiesConstraint.ts, 13, 37))
45+
>otherProperty : Symbol(otherProperty, Decl(intersectionSatisfiesConstraint.ts, 13, 61))
46+
>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 13, 87))
47+
>T : Symbol(T, Decl(intersectionSatisfiesConstraint.ts, 13, 26))
48+
49+
return newParam
50+
>newParam : Symbol(newParam, Decl(intersectionSatisfiesConstraint.ts, 13, 87))
51+
}
52+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tests/cases/compiler/intersectionSatisfiesConstraint.ts] ////
2+
3+
=== intersectionSatisfiesConstraint.ts ===
4+
interface FirstInterface {
5+
commonProperty: number
6+
>commonProperty : number
7+
}
8+
9+
interface SecondInterface {
10+
commonProperty: number
11+
>commonProperty : number
12+
}
13+
14+
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
15+
>myFirstFunction : <T extends FirstInterface | SecondInterface>(param1: T) => void
16+
><T extends FirstInterface | SecondInterface>(param1: T) => { const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 }) mySecondFunction(newParam)} : <T extends FirstInterface | SecondInterface>(param1: T) => void
17+
>param1 : T
18+
19+
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
20+
>newParam : T & { otherProperty: number; }
21+
>otherProperty : number
22+
>Object.assign(param1, { otherProperty: 3 }) : T & { otherProperty: number; }
23+
>Object.assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
24+
>Object : ObjectConstructor
25+
>assign : { <T extends {}, U>(target: T, source: U): T & U; <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
26+
>param1 : T
27+
>{ otherProperty: 3 } : { otherProperty: number; }
28+
>otherProperty : number
29+
>3 : 3
30+
31+
mySecondFunction(newParam)
32+
>mySecondFunction(newParam) : { commonProperty: number; otherProperty: number; }
33+
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
34+
>newParam : (FirstInterface | SecondInterface) & { otherProperty: number; }
35+
}
36+
37+
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
38+
>mySecondFunction : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
39+
><T extends { commonProperty: number, otherProperty: number }>(newParam: T) => { return newParam} : <T extends { commonProperty: number; otherProperty: number; }>(newParam: T) => T
40+
>commonProperty : number
41+
>otherProperty : number
42+
>newParam : T
43+
44+
return newParam
45+
>newParam : T
46+
}
47+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @strict: true
2+
// @lib: esnext
3+
4+
interface FirstInterface {
5+
commonProperty: number
6+
}
7+
8+
interface SecondInterface {
9+
commonProperty: number
10+
}
11+
12+
const myFirstFunction = <T extends FirstInterface | SecondInterface>(param1: T) => {
13+
const newParam: T & { otherProperty: number } = Object.assign(param1, { otherProperty: 3 })
14+
mySecondFunction(newParam)
15+
}
16+
17+
const mySecondFunction = <T extends { commonProperty: number, otherProperty: number }>(newParam: T) => {
18+
return newParam
19+
}

0 commit comments

Comments
 (0)