Skip to content

Commit b0bc68f

Browse files
committed
Add a few more test cases of the "negative" cases
These are the cases where our heuristic makes some compromise that isn't what we would have preferred, but add the unit tests as a way of documenting the current behavior.
1 parent 6f8e37d commit b0bc68f

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// In the abstract, we might prefer the inferred return type annotation to
4+
// be identical to the parameter type (with 2 type parameters).
5+
// Our current heursitic to avoid overly complex types in this case creates
6+
// "overly simple" types, but this tradeoff seems reasonable.
7+
8+
// @isolatedDeclarations: true
9+
// @declaration: true
10+
////export interface Foo<T, U = T[]> {}
11+
////export function foo(x: Foo<string, string[]>) {
12+
//// return x;
13+
////}
14+
15+
verify.codeFix({
16+
description: "Add return type 'Foo<string>'",
17+
index: 0,
18+
newFileContent:
19+
`export interface Foo<T, U = T[]> {}
20+
export function foo(x: Foo<string, string[]>): Foo<string> {
21+
return x;
22+
}`,
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// Our current heursitic to avoid overly verbose generic types
4+
// doesn't handle generic types nested inside other types.
5+
6+
// @isolatedDeclarations: true
7+
// @declaration: true
8+
////export interface Foo<T, U = T[]> {}
9+
////export function foo(x: Map<number, Foo<string>>) {
10+
//// return x;
11+
////}
12+
13+
verify.codeFix({
14+
description: "Add return type 'Map<number, Foo<string, string[]>>'",
15+
index: 0,
16+
newFileContent:
17+
`export interface Foo<T, U = T[]> {}
18+
export function foo(x: Map<number, Foo<string>>): Map<number, Foo<string, string[]>> {
19+
return x;
20+
}`,
21+
});

0 commit comments

Comments
 (0)