Skip to content

Commit c53ccac

Browse files
committed
feat: Implement the implicitUnknown complier flag
1 parent 89386dd commit c53ccac

File tree

6 files changed

+104
-71
lines changed

6 files changed

+104
-71
lines changed

src/compiler/checker.ts

Lines changed: 81 additions & 71 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ namespace ts {
396396
category: Diagnostics.Strict_Type_Checking_Options,
397397
description: Diagnostics.Raise_error_on_expressions_and_declarations_with_an_implied_any_type
398398
},
399+
{
400+
name: "implicitUnknown",
401+
type: "boolean",
402+
showInSimplifiedHelpView: true,
403+
category: Diagnostics.Strict_Type_Checking_Options,
404+
description: Diagnostics.Use_unknown_as_implicit_type
405+
},
399406
{
400407
name: "strictNullChecks",
401408
type: "boolean",

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,10 @@
38993899
"category": "Message",
39003900
"code": 6217
39013901
},
3902+
"Use unknown as implicit type.": {
3903+
"category": "Message",
3904+
"code": 6218
3905+
},
39023906

39033907
"Projects to reference": {
39043908
"category": "Message",

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,6 +4605,8 @@ namespace ts {
46054605
experimentalDecorators?: boolean;
46064606
forceConsistentCasingInFileNames?: boolean;
46074607
/*@internal*/help?: boolean;
4608+
/** Changes the implicit type from `any` to `unknown`. */
4609+
implicitUnknown?: boolean;
46084610
importHelpers?: boolean;
46094611
/*@internal*/init?: boolean;
46104612
inlineSourceMap?: boolean;

src/server/protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,8 @@ namespace ts.server.protocol {
29562956
emitDecoratorMetadata?: boolean;
29572957
experimentalDecorators?: boolean;
29582958
forceConsistentCasingInFileNames?: boolean;
2959+
/** Changes the implicit type from `any` to `unknown`. */
2960+
implicitUnknown?: boolean;
29592961
importHelpers?: boolean;
29602962
inlineSourceMap?: boolean;
29612963
inlineSources?: boolean;

src/testRunner/unittests/services/transpile.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ var x = 0;`, {
260260
options: { compilerOptions: { forceConsistentCasingInFileNames: true }, fileName: "input.js", reportDiagnostics: true }
261261
});
262262

263+
transpilesCorrectly("Supports setting 'implicitUnknown'", "x;", {
264+
options: { compilerOptions: { implicitUnknown: true }, fileName: "input.js", reportDiagnostics: true }
265+
});
266+
263267
transpilesCorrectly("Supports setting 'isolatedModules'", "x;", {
264268
options: { compilerOptions: { isolatedModules: true }, fileName: "input.js", reportDiagnostics: true }
265269
});
@@ -312,6 +316,10 @@ var x = 0;`, {
312316
options: { compilerOptions: { noImplicitAny: true }, fileName: "input.js", reportDiagnostics: true }
313317
});
314318

319+
transpilesCorrectly("Supports setting 'noImplicitAny' and 'implicitUnknown'", "x;", {
320+
options: { compilerOptions: { noImplicitAny: true, implicitUnknown: true }, fileName: "input.js", reportDiagnostics: true }
321+
});
322+
315323
transpilesCorrectly("Supports setting 'noImplicitReturns'", "x;", {
316324
options: { compilerOptions: { noImplicitReturns: true }, fileName: "input.js", reportDiagnostics: true }
317325
});

0 commit comments

Comments
 (0)