From 04d77fe9006dacda43453a9dfd7e615c3dd39012 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 20 Jan 2022 11:33:30 -0800 Subject: [PATCH] Update to TypeScript 4.5.5, fix semantic lints. (#47529) * Update to TypeScript 4.5.5, fix semantic lints. * Remove extra parens. * Remove now-outdated non-null comment around #18217. --- package-lock.json | 6 +++--- package.json | 2 +- src/compiler/checker.ts | 12 ++++++------ src/compiler/commandLineParser.ts | 2 +- src/compiler/debug.ts | 2 +- src/compiler/emitter.ts | 2 +- src/compiler/moduleNameResolver.ts | 2 +- src/compiler/transformers/declarations.ts | 4 ++-- src/compiler/transformers/es2017.ts | 2 +- src/compiler/utilities.ts | 2 +- src/services/completions.ts | 6 +++--- src/services/findAllReferences.ts | 2 +- src/services/navigateTo.ts | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72c34e76a09..724237432f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7686,9 +7686,9 @@ "dev": true }, "typescript": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", - "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", + "version": "4.5.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", + "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==", "dev": true }, "umd": { diff --git a/package.json b/package.json index aafbd543bf8..ffc56b0d24a 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "q": "latest", "source-map-support": "latest", "through2": "latest", - "typescript": "^4.2.3", + "typescript": "^4.5.5", "vinyl": "latest", "vinyl-sourcemaps-apply": "latest", "xml2js": "^0.4.19" diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6de001be183..759eaa1f5d2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8704,7 +8704,7 @@ namespace ts { const isProperty = isPropertyDeclaration(declaration) || isPropertySignature(declaration); const isOptional = includeOptionality && ( - isProperty && !!(declaration as PropertyDeclaration | PropertySignature).questionToken || + isProperty && !!declaration.questionToken || isParameter(declaration) && (!!declaration.questionToken || isJSDocOptionalParameter(declaration)) || isOptionalJSDocPropertyLikeTag(declaration)); @@ -27886,7 +27886,7 @@ namespace ts { const isNodeOpeningLikeElement = isJsxOpeningLikeElement(node); if (isNodeOpeningLikeElement) { - checkGrammarJsxElement(node as JsxOpeningLikeElement); + checkGrammarJsxElement(node); } checkJsxPreconditions(node); @@ -27896,7 +27896,7 @@ namespace ts { // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error. const jsxFactoryRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; const jsxFactoryNamespace = getJsxNamespace(node); - const jsxFactoryLocation = isNodeOpeningLikeElement ? (node as JsxOpeningLikeElement).tagName : node; + const jsxFactoryLocation = isNodeOpeningLikeElement ? node.tagName : node; // allow null as jsxFragmentFactory let jsxFactorySym: Symbol | undefined; @@ -27926,9 +27926,9 @@ namespace ts { } if (isNodeOpeningLikeElement) { - const jsxOpeningLikeNode = node as JsxOpeningLikeElement; + const jsxOpeningLikeNode = node ; const sig = getResolvedSignature(jsxOpeningLikeNode); - checkDeprecatedSignature(sig, node as JsxOpeningLikeElement); + checkDeprecatedSignature(sig, node); checkJsxReturnAssignableToAppropriateBound(getJsxReferenceKind(jsxOpeningLikeNode), getReturnTypeOfSignature(sig), jsxOpeningLikeNode); } } @@ -36988,7 +36988,7 @@ namespace ts { // Don't validate for-in initializer as it is already an error const widenedType = getWidenedTypeForVariableLikeDeclaration(node); if (needCheckInitializer) { - const initializerType = checkExpressionCached(node.initializer!); + const initializerType = checkExpressionCached(node.initializer); if (strictNullChecks && needCheckWidenedType) { checkNonNullNonVoidType(initializerType, node); } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 57cd2f3c309..89d131508cb 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -3156,7 +3156,7 @@ namespace ts { if (isCompilerOptionsValue(opt, value)) { const optType = opt.type; if (optType === "list" && isArray(value)) { - return convertJsonOptionOfListType(opt as CommandLineOptionOfListType, value, basePath, errors); + return convertJsonOptionOfListType(opt , value, basePath, errors); } else if (!isString(optType)) { return convertJsonOptionOfCustomType(opt as CommandLineOptionOfCustomType, value as string, errors); diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index 5d22b0fe798..36a402b3340 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -654,7 +654,7 @@ namespace ts { if (text === undefined) { const parseNode = getParseTreeNode(this); const sourceFile = parseNode && getSourceFileOfNode(parseNode); - text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode!, includeTrivia) : ""; + text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; map?.set(this, text); } return text; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 445537d3de8..cbc1d218dc6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1051,7 +1051,7 @@ namespace ts { writeLine(); const pos = writer.getTextPos(); const savedSections = bundleFileInfo && bundleFileInfo.sections; - if (savedSections) bundleFileInfo!.sections = []; + if (savedSections) bundleFileInfo.sections = []; print(EmitHint.Unspecified, prepend, /*sourceFile*/ undefined); if (bundleFileInfo) { const newSections = bundleFileInfo.sections; diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 0e2cff7d004..5ea72a6bbf2 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -977,7 +977,7 @@ namespace ts { perFolderCache.set(moduleName, resolutionMode, result); if (!isExternalModuleNameRelative(moduleName)) { // put result in per-module name cache - cache!.getOrCreateCacheForModuleName(moduleName, resolutionMode, redirectedReference).set(containingDirectory, result); + cache.getOrCreateCacheForModuleName(moduleName, resolutionMode, redirectedReference).set(containingDirectory, result); } } } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index ab0294f9b44..b17d861cc51 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -878,7 +878,7 @@ namespace ts { } if (canProduceDiagnostic && !suppressNewDiagnosticContexts) { - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input); } if (isTypeQueryNode(input)) { @@ -1073,7 +1073,7 @@ namespace ts { function cleanup(returnValue: T | undefined): T | undefined { if (returnValue && canProduceDiagnostic && hasDynamicName(input as Declaration)) { - checkName(input as DeclarationDiagnosticProducing); + checkName(input); } if (isEnclosingDeclaration(input)) { enclosingDeclaration = previousEnclosingDeclaration; diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index ade1d41b010..50c4fa62c0d 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -528,7 +528,7 @@ namespace ts { inHasLexicalThisContext(), hasLexicalArguments, promiseConstructor, - transformAsyncFunctionBodyWorker(node.body!) + transformAsyncFunctionBodyWorker(node.body) ); const declarations = endLexicalEnvironment(); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e4dcbe85aee..691a965ee66 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2260,7 +2260,7 @@ namespace ts { const e = isBinaryExpression(initializer) && (initializer.operatorToken.kind === SyntaxKind.BarBarToken || initializer.operatorToken.kind === SyntaxKind.QuestionQuestionToken) && getExpandoInitializer(initializer.right, isPrototypeAssignment); - if (e && isSameEntityName(name, (initializer as BinaryExpression).left)) { + if (e && isSameEntityName(name, initializer.left)) { return e; } } diff --git a/src/services/completions.ts b/src/services/completions.ts index d9e856c1958..49914e49732 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2257,7 +2257,7 @@ namespace ts.Completions { const attrsType = jsxContainer && typeChecker.getContextualType(jsxContainer.attributes); if (!attrsType) return GlobalsSearch.Continue; const completionsType = jsxContainer && typeChecker.getContextualType(jsxContainer.attributes, ContextFlags.Completions); - symbols = concatenate(symbols, filterJsxAttributes(getPropertiesForObjectExpression(attrsType, completionsType, jsxContainer!.attributes, typeChecker), jsxContainer!.attributes.properties)); + symbols = concatenate(symbols, filterJsxAttributes(getPropertiesForObjectExpression(attrsType, completionsType, jsxContainer.attributes, typeChecker), jsxContainer.attributes.properties)); setSortTextToOptionalMember(); completionKind = CompletionKind.MemberLike; isNewIdentifierLocation = false; @@ -3587,8 +3587,8 @@ namespace ts.Completions { export function getPropertiesForObjectExpression(contextualType: Type, completionsType: Type | undefined, obj: ObjectLiteralExpression | JsxAttributes, checker: TypeChecker): Symbol[] { const hasCompletionsType = completionsType && completionsType !== contextualType; - const type = hasCompletionsType && !(completionsType!.flags & TypeFlags.AnyOrUnknown) - ? checker.getUnionType([contextualType, completionsType!]) + const type = hasCompletionsType && !(completionsType.flags & TypeFlags.AnyOrUnknown) + ? checker.getUnionType([contextualType, completionsType]) : contextualType; const properties = getApparentProperties(type, obj, checker); diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 9f6baf0cc73..5a8a60452b3 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1276,7 +1276,7 @@ namespace ts.FindAllReferences { - But if the parent has `export as namespace`, the symbol is globally visible through that namespace. */ const exposedByParent = parent && !(symbol.flags & SymbolFlags.TypeParameter); - if (exposedByParent && !(isExternalModuleSymbol(parent!) && !parent!.globalExports)) { + if (exposedByParent && !(isExternalModuleSymbol(parent) && !parent.globalExports)) { return undefined; } diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index 709dd80eb90..462d4fd0ac3 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -130,7 +130,7 @@ namespace ts.NavigateTo { textSpan: createTextSpanFromNode(declaration), // TODO(jfreeman): What should be the containerName when the container has a computed name? containerName: containerName ? (containerName as Identifier).text : "", - containerKind: containerName ? getNodeKind(container!) : ScriptElementKind.unknown, // TODO: GH#18217 Just use `container ? ...` + containerKind: containerName ? getNodeKind(container) : ScriptElementKind.unknown, }; } }