Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
blickly committed Aug 17, 2024
commit b0bc68fcabd64d09ac7020446d670d56234a97b5
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path='fourslash.ts'/>
Comment thread
sandersn marked this conversation as resolved.

// In the abstract, we might prefer the inferred return type annotation to
// be identical to the parameter type (with 2 type parameters).
// Our current heursitic to avoid overly complex types in this case creates
Comment thread
blickly marked this conversation as resolved.
Outdated
// "overly simple" types, but this tradeoff seems reasonable.
Comment thread
sandersn marked this conversation as resolved.

// @isolatedDeclarations: true
// @declaration: true
////export interface Foo<T, U = T[]> {}
////export function foo(x: Foo<string, string[]>) {
//// return x;
////}

verify.codeFix({
description: "Add return type 'Foo<string>'",
index: 0,
newFileContent:
`export interface Foo<T, U = T[]> {}
export function foo(x: Foo<string, string[]>): Foo<string> {
return x;
}`,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts'/>

// Our current heursitic to avoid overly verbose generic types
// doesn't handle generic types nested inside other types.

// @isolatedDeclarations: true
// @declaration: true
////export interface Foo<T, U = T[]> {}
////export function foo(x: Map<number, Foo<string>>) {
//// return x;
////}

verify.codeFix({
description: "Add return type 'Map<number, Foo<string, string[]>>'",
index: 0,
newFileContent:
`export interface Foo<T, U = T[]> {}
export function foo(x: Map<number, Foo<string>>): Map<number, Foo<string, string[]>> {
return x;
}`,
});