Skip to content

Commit dddbae5

Browse files
committed
Simplify TypeNode parsing
1 parent 09c7b6d commit dddbae5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

rules/noUnnecessaryTypeAnnotationRule.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,9 @@ function walk(ctx: Lint.WalkContext<IOptions>, checker: ts.TypeChecker) {
302302
}
303303

304304
function removeSignatureReturn(str: string): string {
305-
const sourceFile = ts.createSourceFile('tmp.ts', `var a:${str}`, ts.ScriptTarget.ESNext);
306-
const signature = <ts.FunctionOrConstructorTypeNode>(<ts.VariableStatement>sourceFile.statements[0])
307-
.declarationList.declarations[0].type!;
308-
return sourceFile.text.substring(6, signature.parameters.end + 1);
305+
const sourceFile = ts.createSourceFile('tmp.ts', `type T=${str}`, ts.ScriptTarget.ESNext);
306+
const signature = <ts.FunctionOrConstructorTypeNode>(<ts.TypeAliasDeclaration>sourceFile.statements[0]).type;
307+
return sourceFile.text.substring(7, signature.parameters.end + 1);
309308
}
310309

311310
function getSignaturesOfType(type: ts.Type): ts.Signature[] {

0 commit comments

Comments
 (0)