Skip to content

Commit 4f7da16

Browse files
Fix unnecessary non-null assertions caught by newer ts-eslint (#57070)
Co-authored-by: Sheetal Nandi <[email protected]>
1 parent 3f8707d commit 4f7da16

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

src/compiler/checker.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7831,7 +7831,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
78317831
if (context.tracker.canTrackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
78327832
trackComputedName(node.expression, context.enclosingDeclaration, context);
78337833
}
7834-
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, /*context*/ undefined, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
7834+
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, /*context*/ undefined, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags);
78357835
if (isBindingElement(visited)) {
78367836
visited = factory.updateBindingElement(
78377837
visited,
@@ -32643,7 +32643,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3264332643
// Find the first enclosing class that has the declaring classes of the protected constituents
3264432644
// of the property as base classes
3264532645
let enclosingClass = forEachEnclosingClass(location, enclosingDeclaration => {
32646-
const enclosingClass = getDeclaredTypeOfSymbol(getSymbolOfDeclaration(enclosingDeclaration)!) as InterfaceType;
32646+
const enclosingClass = getDeclaredTypeOfSymbol(getSymbolOfDeclaration(enclosingDeclaration)) as InterfaceType;
3264732647
return isClassDerivedFromDeclaringClasses(enclosingClass, prop, writing);
3264832648
});
3264932649
// A protected property is accessible if the property is within the declaring class or classes derived from it
@@ -36292,7 +36292,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3629236292
return getTypeOfSymbol(symbol);
3629336293
}
3629436294
else {
36295-
const symbol = getSymbolOfDeclaration(container)!;
36295+
const symbol = getSymbolOfDeclaration(container);
3629636296
return getTypeOfSymbol(symbol);
3629736297
}
3629836298
}
@@ -40082,7 +40082,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4008240082
// TypeScript 1.0 spec (April 2014)
4008340083
// 3.7.4: An object type can contain at most one string index signature and one numeric index signature.
4008440084
// 8.5: A class declaration can have at most one string index member declaration and one numeric index member declaration
40085-
const indexSymbol = getIndexSymbol(getSymbolOfDeclaration(node)!);
40085+
const indexSymbol = getIndexSymbol(getSymbolOfDeclaration(node));
4008640086
if (indexSymbol?.declarations) {
4008740087
const indexSignatureMap = new Map<TypeId, { type: Type; declarations: IndexSignatureDeclaration[]; }>();
4008840088
for (const declaration of (indexSymbol.declarations as IndexSignatureDeclaration[])) {
@@ -41039,7 +41039,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4103941039
case SyntaxKind.NamespaceImport:
4104041040
case SyntaxKind.ImportClause:
4104141041
let result = DeclarationSpaces.None;
41042-
const target = resolveAlias(getSymbolOfDeclaration(d as ImportEqualsDeclaration | NamespaceImport | ImportClause | ExportAssignment | BinaryExpression)!);
41042+
const target = resolveAlias(getSymbolOfDeclaration(d as ImportEqualsDeclaration | NamespaceImport | ImportClause | ExportAssignment | BinaryExpression));
4104341043
forEach(target.declarations, d => {
4104441044
result |= getDeclarationSpaces(d);
4104541045
});
@@ -47553,7 +47553,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4755347553

4755447554
if (isDeclarationNameOrImportPropertyName(node)) {
4755547555
// This is a declaration, call getSymbolOfNode
47556-
const parentSymbol = getSymbolOfDeclaration(parent as Declaration)!;
47556+
const parentSymbol = getSymbolOfDeclaration(parent as Declaration);
4755747557
return isImportOrExportSpecifier(node.parent) && node.parent.propertyName === node
4755847558
? getImmediateAliasedSymbol(parentSymbol)
4755947559
: parentSymbol;

src/compiler/emitter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
30683068
// If the number will be printed verbatim and it doesn't already contain a dot or an exponent indicator, add one
30693069
// if the expression doesn't have any comments that will be emitted.
30703070
return !(expression.numericLiteralFlags & TokenFlags.WithSpecifier)
3071-
&& !text.includes(tokenToString(SyntaxKind.DotToken)!)
3071+
&& !text.includes(tokenToString(SyntaxKind.DotToken))
30723072
&& !text.includes(String.fromCharCode(CharacterCodes.E))
30733073
&& !text.includes(String.fromCharCode(CharacterCodes.e));
30743074
}

src/harness/client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class SessionClient implements LanguageService {
175175
let foundResponseMessage = false;
176176
let response!: T;
177177
while (!foundResponseMessage) {
178-
const lastMessage = this.messages.dequeue()!;
178+
const lastMessage = this.messages.dequeue();
179179
Debug.assert(!!lastMessage, "Did not receive any responses.");
180180
const responseBody = extractMessage(lastMessage);
181181
try {
@@ -842,7 +842,7 @@ export class SessionClient implements LanguageService {
842842

843843
const request = this.processRequest<protocol.GetMoveToRefactoringFileSuggestionsRequest>(protocol.CommandTypes.GetMoveToRefactoringFileSuggestions, args);
844844
const response = this.processResponse<protocol.GetMoveToRefactoringFileSuggestions>(request);
845-
return { newFileName: response.body?.newFileName, files: response.body?.files }!;
845+
return { newFileName: response.body?.newFileName, files: response.body?.files };
846846
}
847847

848848
getEditsForRefactor(

src/services/completions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5369,7 +5369,7 @@ function getContextualKeywords(
53695369
&& tokenLine === currentLine
53705370
) {
53715371
entries.push({
5372-
name: tokenToString(SyntaxKind.AssertKeyword)!,
5372+
name: tokenToString(SyntaxKind.AssertKeyword),
53735373
kind: ScriptElementKind.keyword,
53745374
kindModifiers: ScriptElementKindModifier.none,
53755375
sortText: SortText.GlobalsOrKeywords,

src/services/documentRegistry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole
327327
// the script snapshot. If so, update it appropriately. Otherwise, we can just
328328
// return it as is.
329329
if (entry.sourceFile.version !== version) {
330-
entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot!)); // TODO: GH#18217
330+
entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot));
331331
if (externalCache) {
332332
externalCache.setDocument(keyWithMode, path, entry.sourceFile);
333333
}

src/services/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ export function isInsideJsxElement(sourceFile: SourceFile, position: number): bo
19581958
/** @internal */
19591959
export function findPrecedingMatchingToken(token: Node, matchingTokenKind: SyntaxKind.OpenBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.OpenBracketToken, sourceFile: SourceFile) {
19601960
const closeTokenText = tokenToString(token.kind)!;
1961-
const matchingTokenText = tokenToString(matchingTokenKind)!;
1961+
const matchingTokenText = tokenToString(matchingTokenKind);
19621962
const tokenFullStart = token.getFullStart();
19631963
// Text-scan based fast path - can be bamboozled by comments and other trivia, but often provides
19641964
// a good, fast approximation without too much extra work in the cases where it fails.

src/testRunner/unittests/helpers/baseline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export function baselineBuildInfo(
355355
if (!buildInfoPath || !sys.writtenFiles!.has(toPathWithSystem(sys, buildInfoPath))) return;
356356
if (!sys.fileExists(buildInfoPath)) return;
357357

358-
const buildInfo = ts.getBuildInfo(buildInfoPath, (originalReadCall || sys.readFile).call(sys, buildInfoPath, "utf8")!);
358+
const buildInfo = ts.getBuildInfo(buildInfoPath, (originalReadCall || sys.readFile).call(sys, buildInfoPath, "utf8"));
359359
if (!buildInfo) return sys.writeFile(`${buildInfoPath}.baseline.txt`, "Error reading valid buildinfo file");
360360
generateBuildInfoProgramBaseline(sys, buildInfoPath, buildInfo);
361361

src/testRunner/unittests/tsbuild/outFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ ${internal} enum internalEnum { a, b, c }`,
608608
fs.writeFileSync(
609609
"/src/third/tsconfig.json",
610610
jsonToReadableText({
611-
...JSON.parse(fs.readFileSync("/src/third/tsconfig.json", "utf-8")!),
611+
...JSON.parse(fs.readFileSync("/src/third/tsconfig.json", "utf-8")),
612612
references: [{ path: "../second", prepend: true }],
613613
}),
614614
);

src/testRunner/unittests/typeParameterIsPossiblyReferenced.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("unittests :: internalApi :: typeParameterIsPossiblyReferenced", () =>
3232
.type as ts.TypeQueryNode // typeof a
3333
;
3434
const typeParameterDecl = (file.statements[0] as ts.FunctionDeclaration).typeParameters![0]; // T in f<T>
35-
const typeParameter = checker.getTypeAtLocation(typeParameterDecl)! as ts.TypeParameter;
35+
const typeParameter = checker.getTypeAtLocation(typeParameterDecl) as ts.TypeParameter;
3636
const isReferenced = checker.isTypeParameterPossiblyReferenced(typeParameter, typeQueryNode);
3737
assert.ok(isReferenced, "Type parameter is referenced in type query node");
3838
});

0 commit comments

Comments
 (0)