Skip to content

Commit 33b1561

Browse files
h-jooandrewbranch
andauthored
Add a code fixer for --isolatedDeclarations errors (#58260)
Co-authored-by: Andrew Branch <[email protected]>
1 parent 749bd83 commit 33b1561

File tree

58 files changed

+2696
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2696
-6
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16111611
getBaseTypes,
16121612
getBaseTypeOfLiteralType,
16131613
getWidenedType,
1614+
getWidenedLiteralType,
16141615
getTypeFromTypeNode: nodeIn => {
16151616
const node = getParseTreeNode(nodeIn, isTypeNode);
16161617
return node ? getTypeFromTypeNode(node) : errorType;

src/compiler/diagnosticMessages.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7336,6 +7336,46 @@
73367336
"category": "Message",
73377337
"code": 90061
73387338
},
7339+
"Add annotation of type '{0}'": {
7340+
"category": "Message",
7341+
"code": 90062
7342+
},
7343+
"Add return type '{0}'": {
7344+
"category": "Message",
7345+
"code": 90063
7346+
},
7347+
"Extract base class to variable": {
7348+
"category": "Message",
7349+
"code": 90064
7350+
},
7351+
"Extract default export to variable": {
7352+
"category": "Message",
7353+
"code": 90065
7354+
},
7355+
"Extract binding expressions to variable": {
7356+
"category": "Message",
7357+
"code": 90066
7358+
},
7359+
"Add all missing type annotations": {
7360+
"category": "Message",
7361+
"code": 90067
7362+
},
7363+
"Add satisfies and an inline type assertion with '{0}'": {
7364+
"category": "Message",
7365+
"code": 90068
7366+
},
7367+
"Extract to variable and replace with '{0} as typeof {0}'": {
7368+
"category": "Message",
7369+
"code": 90069
7370+
},
7371+
"Mark array literal as const": {
7372+
"category": "Message",
7373+
"code": 90070
7374+
},
7375+
"Annotate types of properties expando function in a namespace": {
7376+
"category": "Message",
7377+
"code": 90071
7378+
},
73397379

73407380
"Convert function to an ES2015 class": {
73417381
"category": "Message",

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5022,6 +5022,8 @@ export interface TypeChecker {
50225022
getBaseTypeOfLiteralType(type: Type): Type;
50235023
getWidenedType(type: Type): Type;
50245024
/** @internal */
5025+
getWidenedLiteralType(type: Type): Type;
5026+
/** @internal */
50255027
getPromisedTypeOfPromise(promise: Type, errorNode?: Node): Type | undefined;
50265028
/** @internal */
50275029
getAwaitedType(type: Type): Type | undefined;

src/services/_namespaces/ts.codefix.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export * from "../codefixes/fixUnreachableCode";
5050
export * from "../codefixes/fixUnusedLabel";
5151
export * from "../codefixes/fixJSDocTypes";
5252
export * from "../codefixes/fixMissingCallParentheses";
53+
export * from "../codefixes/fixMissingTypeAnnotationOnExports";
5354
export * from "../codefixes/fixAwaitInSyncFunction";
5455
export * from "../codefixes/fixPropertyOverrideAccessor";
5556
export * from "../codefixes/inferFromUsage";

src/services/codeFixProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
DiagnosticWithLocation,
1919
FileTextChanges,
2020
flatMap,
21+
getEmitDeclarations,
2122
isString,
2223
map,
2324
TextChange,
@@ -124,9 +125,15 @@ export function eachDiagnostic(context: CodeFixAllContext, errorCodes: readonly
124125
}
125126

126127
function getDiagnostics({ program, sourceFile, cancellationToken }: CodeFixContextBase) {
127-
return [
128+
const diagnostics = [
128129
...program.getSemanticDiagnostics(sourceFile, cancellationToken),
129130
...program.getSyntacticDiagnostics(sourceFile, cancellationToken),
130131
...computeSuggestionDiagnostics(sourceFile, program, cancellationToken),
131132
];
133+
if (getEmitDeclarations(program.getCompilerOptions())) {
134+
diagnostics.push(
135+
...program.getDeclarationDiagnostics(sourceFile, cancellationToken),
136+
);
137+
}
138+
return diagnostics;
132139
}

0 commit comments

Comments
 (0)