Skip to content

Commit

Permalink
Add a fixer to fix type errors for --isolatedDeclarations
Browse files Browse the repository at this point in the history
This code fixer fixes the following patterns.

1. Adding missing types on places that type can be explicitly annotated
2. Adding satisfies with type assertion on a value.
3. Create a namespace for expando functions and declare the property on
   the namespace.
4. Factor out expressions in heritage clauses (class B extends <expression>)
   and give them separate names.

Signed-off-by: Hana Joo <hanajoo@google.com>
  • Loading branch information
h-joo committed Apr 19, 2024
1 parent c50ec79 commit 4e506f9
Show file tree
Hide file tree
Showing 52 changed files with 2,564 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/compiler/diagnosticMessages.json
Expand Up @@ -7184,6 +7184,46 @@
"category": "Message",
"code": 90061
},
"Add annotation of type '{0}'": {
"category": "Message",
"code": 90062
},
"Add return type '{0}'": {
"category": "Message",
"code": 90063
},
"Extract base class to variable": {
"category": "Message",
"code": 90064
},
"Extract default export to variable": {
"category": "Message",
"code": 90065
},
"Extract binding expressions to variable": {
"category": "Message",
"code": 90066
},
"Add all missing type annotations": {
"category": "Message",
"code": 90067
},
"Add satisfies and an inline type assertion with '{0}'": {
"category": "Message",
"code": 90068
},
"Extract to variable and replace with '{0} typeof {0}'": {
"category": "Message",
"code": 90069
},
"Mark array literal as const": {
"category": "Message",
"code": 90070
},
"Annotate types of properties expando function in a namespace": {
"category": "Message",
"code": 90071
},

"Convert function to an ES2015 class": {
"category": "Message",
Expand Down
1 change: 1 addition & 0 deletions src/services/_namespaces/ts.codefix.ts
Expand Up @@ -50,6 +50,7 @@ export * from "../codefixes/fixUnreachableCode";
export * from "../codefixes/fixUnusedLabel";
export * from "../codefixes/fixJSDocTypes";
export * from "../codefixes/fixMissingCallParentheses";
export * from "../codefixes/fixMissingTypeAnnotationOnExports";
export * from "../codefixes/fixAwaitInSyncFunction";
export * from "../codefixes/fixPropertyOverrideAccessor";
export * from "../codefixes/inferFromUsage";
Expand Down
1 change: 1 addition & 0 deletions src/services/codeFixProvider.ts
Expand Up @@ -127,6 +127,7 @@ function getDiagnostics({ program, sourceFile, cancellationToken }: CodeFixConte
return [
...program.getSemanticDiagnostics(sourceFile, cancellationToken),
...program.getSyntacticDiagnostics(sourceFile, cancellationToken),
...program.getDeclarationDiagnostics(sourceFile, cancellationToken),
...computeSuggestionDiagnostics(sourceFile, program, cancellationToken),
];
}

0 comments on commit 4e506f9

Please sign in to comment.