-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Remove unnecessary type assertions #62969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Remove unnecessary type assertions #62969
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
1 similar comment
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request removes unnecessary type assertions across the TypeScript codebase that were identified by improvements to the @typescript-eslint/no-unnecessary-type-assertion lint rule. The changes are purely cosmetic, removing as Type assertions where TypeScript's type inference already provides the correct type information.
Key changes:
- Removal of redundant type assertions in type guard contexts (e.g., after
flags & TypeFlags.TypeParameterchecks) - Elimination of unnecessary casts where function signatures already accept the broader type
- Cleanup of assertions where factory methods return the correct specific type
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/testRunner/unittests/tsserver/inlayHints.ts | Removed unnecessary assertion on preferences object |
| src/testRunner/projectsRunner.ts | Removed redundant string assertion on baseline content |
| src/services/symbolDisplay.ts | Removed type assertion where type parameter check provides correct type |
| src/services/stringCompletions.ts | Removed host interface assertions where type is already compatible |
| src/services/services.ts | Removed SyntaxKind assertion on Number() result |
| src/services/getEditsForFileRename.ts | Removed ModuleResolutionHost assertion |
| src/services/findAllReferences.ts | Removed assertion on findAncestor result with type guard |
| src/services/completions.ts | Removed ObjectTypeDeclaration assertion on findAncestor |
| src/services/codefixes/generateAccessors.ts | Removed assertion on declaration.name.text |
| src/services/codefixes/fixUnreferenceableDecoratorMetadata.ts | Removed assertion on or() predicate result |
| src/services/classifier.ts | Removed ClassificationType assertion on array access |
| src/server/utilitiesPublic.ts | Removed NormalizedPath[] assertion on concat |
| src/server/session.ts | Removed string assertion on symlinkedPath |
| src/server/project.ts | Removed SortedReadonlyArray assertion on emptyArray |
| src/server/editorServices.ts | Removed ProgramUpdateLevel assertion on Math.max result |
| src/compiler/utilitiesPublic.ts | Removed Identifier assertion where type is already known |
| src/compiler/utilities.ts | Removed NonNullable assertion on generic parameter |
| src/compiler/tsbuildPublic.ts | Removed CompilerHost & ReadBuildProgramHost assertion |
| src/compiler/transformers/ts.ts | Removed ModuleDeclaration assertion after type check |
| src/compiler/transformers/es2018.ts | Removed NodeCheckFlags assertion on literal 0 |
| src/compiler/symbolWalker.ts | Removed TypeParameter assertion after flags check |
| src/compiler/parser.ts | Removed callback type assertions for forEachChild |
| src/compiler/emitter.ts | Removed DotToken, Modifier[], and Decorator[] assertions |
| src/compiler/checker.ts | Removed 50+ TypeParameter, UnionType, and other type assertions after flag checks |
| src/compiler/binder.ts | Removed Identifier assertions where function accepts broader Node type |
While testing my changes to the @typescript-eslint/no-unnecessary-type-assertion lint rule on this repo, I found these unnecessary type assertions that can be removed without impacting runtime behaviour or triggering TS errors.
typescript-eslint/typescript-eslint#11789