Skip to content

Commit 0c8d85f

Browse files
committed
Test that type parameters used in constraints are passed along
1 parent fe015ef commit 0c8d85f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/harness/unittests/extractMethods.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,13 @@ namespace A {
574574
[#|t1.toString();
575575
t2.toString();|]
576576
}
577+
}`);
578+
// Confirm that the constraint is preserved.
579+
testExtractMethod("extractMethod15",
580+
`function F<T>(t1: T) {
581+
function F<U extends T[]>(t2: U) {
582+
[#|t2.toString();|]
583+
}
577584
}`);
578585
});
579586

@@ -590,7 +597,7 @@ namespace A {
590597
path: "/a.ts",
591598
content: t.source
592599
};
593-
const host = projectSystem.createServerHost([f]);
600+
const host = projectSystem.createServerHost([f, projectSystem.libFile]);
594601
const projectService = projectSystem.createProjectService(host);
595602
projectService.openClientFile(f.path);
596603
const program = projectService.inferredProjects[0].getLanguageService().getProgram();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ==ORIGINAL==
2+
function F<T>(t1: T) {
3+
function F<U extends T[]>(t2: U) {
4+
t2.toString();
5+
}
6+
}
7+
// ==SCOPE::function 'F'==
8+
function F<T>(t1: T) {
9+
function F<U extends T[]>(t2: U) {
10+
newFunction();
11+
12+
function newFunction() {
13+
t2.toString();
14+
}
15+
}
16+
}
17+
// ==SCOPE::function 'F'==
18+
function F<T>(t1: T) {
19+
function F<U extends T[]>(t2: U) {
20+
newFunction<U>(t2);
21+
}
22+
23+
function newFunction<U extends T[]>(t2: U) {
24+
t2.toString();
25+
}
26+
}
27+
// ==SCOPE::global scope==
28+
function F<T>(t1: T) {
29+
function F<U extends T[]>(t2: U) {
30+
newFunction<T, U>(t2);
31+
}
32+
}
33+
function newFunction<T, U extends T[]>(t2: U) {
34+
t2.toString();
35+
}

0 commit comments

Comments
 (0)