Skip to content

Commit 51d3446

Browse files
authored
feat(47281): use unknown type instead of any (#47308)
1 parent 55e2e15 commit 51d3446

11 files changed

+12
-13
lines changed

src/services/codefixes/helpers.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ namespace ts.codefix {
359359
/*dotDotDotToken*/ undefined,
360360
/*name*/ names && names[i] || `arg${i}`,
361361
/*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
362-
/*type*/ inJs ? undefined : types && types[i] || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword),
362+
/*type*/ inJs ? undefined : types && types[i] || factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword),
363363
/*initializer*/ undefined);
364364
parameters.push(newParameter);
365365
}
@@ -398,14 +398,13 @@ namespace ts.codefix {
398398
const parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, /* types */ undefined, minArgumentCount, /*inJs*/ false);
399399

400400
if (someSigHasRestParameter) {
401-
const anyArrayType = factory.createArrayTypeNode(factory.createKeywordTypeNode(SyntaxKind.AnyKeyword));
402401
const restParameter = factory.createParameterDeclaration(
403402
/*decorators*/ undefined,
404403
/*modifiers*/ undefined,
405404
factory.createToken(SyntaxKind.DotDotDotToken),
406405
maxArgsParameterSymbolNames[maxNonRestArgs] || "rest",
407406
/*questionToken*/ maxNonRestArgs >= minArgumentCount ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
408-
anyArrayType,
407+
factory.createArrayTypeNode(factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword)),
409408
/*initializer*/ undefined);
410409
parameters.push(restParameter);
411410
}

tests/cases/fourslash/codeFixClassExtendAbstractMethod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class C extends A {
2626
f(a: number, b: string): this;
2727
f(a: string, b: number): Function;
2828
f(a: string): Function;
29-
f(a: any, b?: any): boolean | Function | this {
29+
f(a: unknown, b?: unknown): boolean | Function | this {
3030
throw new Error("Method not implemented.");
3131
}
3232
foo(): number {

tests/cases/fourslash/codeFixClassImplementInterfaceComputedPropertyNameWellKnownSymbols.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class C implements I<number> {
6262
[Symbol.toPrimitive](hint: "number"): number;
6363
[Symbol.toPrimitive](hint: "default"): number;
6464
[Symbol.toPrimitive](hint: "string"): string;
65-
[Symbol.toPrimitive](hint: any): string | number {
65+
[Symbol.toPrimitive](hint: unknown): string | number {
6666
throw new Error("Method not implemented.");
6767
}
6868
[Symbol.toStringTag]: string;

tests/cases/fourslash/codeFixClassImplementInterfaceMethodTypePredicate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ verify.codeFix({
1818
class C implements I {
1919
f(i: any): i is I;
2020
f(): this is I;
21-
f(i?: any): boolean {
21+
f(i?: unknown): boolean {
2222
throw new Error("Method not implemented.");
2323
}
2424
}`,

tests/cases/fourslash/codeFixClassImplementInterfaceMultipleSignatures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class C implements I {
2121
method(a: number, b: string): boolean;
2222
method(a: string, b: number): Function;
2323
method(a: string): Function;
24-
method(a: any, b?: any): boolean | Function {
24+
method(a: unknown, b?: unknown): boolean | Function {
2525
throw new Error("Method not implemented.");
2626
}
2727
}`,

tests/cases/fourslash/codeFixClassImplementInterfaceMultipleSignaturesRest1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class C implements I {
2121
method(a: number, ...b: string[]): boolean;
2222
method(a: string, ...b: number[]): Function;
2323
method(a: string): Function;
24-
method(a: any, ...b?: any[]): boolean | Function {
24+
method(a: unknown, ...b?: unknown[]): boolean | Function {
2525
throw new Error("Method not implemented.");
2626
}
2727
}`,

tests/cases/fourslash/codeFixClassImplementInterfaceMultipleSignaturesRest2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class C implements I {
2121
method(a: number, ...b: string[]): boolean;
2222
method(a: string, b: number): Function;
2323
method(a: string): Function;
24-
method(a: any, b?: any, ...rest?: any[]): boolean | Function {
24+
method(a: unknown, b?: unknown, ...rest?: unknown[]): boolean | Function {
2525
throw new Error("Method not implemented.");
2626
}
2727
}`,

tests/cases/fourslash/completionsOverridingMethod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ verify.completions({
264264
insertText:
265265
`foo(a: string): string;
266266
foo(a: undefined, b: number): string;
267-
foo(a: any, b?: any): string {
267+
foo(a: unknown, b?: unknown): string {
268268
}`,
269269
}
270270
],

tests/cases/fourslash/completionsOverridingMethod10.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ verify.completions({
5656
insertText:
5757
`c(a: string): string;
5858
c(a: number): number;
59-
c(a: any): string | number {
59+
c(a: unknown): string | number {
6060
}`,
6161
},
6262
],

tests/cases/fourslash/completionsOverridingMethod11.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ verify.completions({
6262
insertText:
6363
`c(a: string): string
6464
c(a: number): number
65-
c(a: any): string | number {
65+
c(a: unknown): string | number {
6666
}`,
6767
},
6868
],

tests/cases/fourslash/completionsOverridingMethod6.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ verify.completions({
9090
insertText:
9191
`fun(a: number): number;
9292
public fun(a: undefined, b: string): number;
93-
public fun(a: any, b?: any): number {
93+
public fun(a: unknown, b?: unknown): number {
9494
}`,
9595
},
9696
],

0 commit comments

Comments
 (0)