Skip to content

Commit

Permalink
fix: don't expand existing type with explicit any (#1279)
Browse files Browse the repository at this point in the history
* fix: don't expand existing type with explicit any

* fix: doc comment
  • Loading branch information
JoshuaKGoldberg authored Aug 18, 2023
1 parent dbc20ac commit dea0ef7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mutations/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export const createTypeAdditionMutation = (
declaredType: ts.Type,
allAssignedTypes: ReadonlyArray<ts.Type>,
): TextInsertMutation | TextSwapMutation | undefined => {
// Declared 'any' types inherently can't be incomplete
if (tsutils.isTypeFlagSet(declaredType, ts.TypeFlags.Any)) {
return undefined;
}

// Find any missing flags and symbols (a.k.a. types)
const { missingFlags, missingTypes } = collectUsageFlagsAndSymbols(request, declaredType, allAssignedTypes);

Expand Down
4 changes: 4 additions & 0 deletions test/cases/fixes/incompleteTypes/parameterTypes/expected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
function passesStringOrBoolean(input: string | boolean) {
takesStringOrBoolean(input);
}

function takesAny(
input: any = {}
) {}
})()
4 changes: 4 additions & 0 deletions test/cases/fixes/incompleteTypes/parameterTypes/original.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
function passesStringOrBoolean(input: string | boolean) {
takesStringOrBoolean(input);
}

function takesAny(
input: any = {}
) {}
})()

0 comments on commit dea0ef7

Please sign in to comment.