Skip to content

Commit 88d12e4

Browse files
authored
refactor: remove workaround for TS versions earlier than 4.8 (#25777)
Cleans up some workarounds that were put in place to support version of TypeScript earlier than 4.8.
1 parent d75a87d commit 88d12e4

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/cdk/schematics/update-tool/component-resource-collector.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ export class ComponentResourceCollector {
5454
}
5555

5656
private _visitClassDeclaration(node: ts.ClassDeclaration) {
57-
// TODO(crisbeto): in TS 4.8 the `decorators` are combined with the `modifiers` array.
58-
// Once we drop support for older versions, we can rely exclusively on `getDecorators`.
59-
const decorators = ts.getDecorators?.(node) || node.decorators;
57+
const decorators = ts.getDecorators(node);
6058

6159
if (!decorators || !decorators.length) {
6260
return;

src/material/schematics/ng-update/migrations/hammer-gestures-v9/hammer-gestures-migration.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ interface PackageJson {
5656
dependencies: Record<string, string>;
5757
}
5858

59-
/**
60-
* Used to temporarily cast types to `any` to unblock the upgrade to TypeScript 4.8.
61-
* TODO(crisbeto): Remove this once https://github.com/angular/angular-cli/pull/23764 is released.
62-
*/
63-
type Ts48MigrationAny = any;
64-
6559
export class HammerGesturesMigration extends DevkitMigration<null> {
6660
// The migration is enabled when v9 or v10 are targeted, but actual targets are only
6761
// migrated if they are not test targets. We cannot migrate test targets since they have
@@ -736,7 +730,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
736730

737731
const sourceFile = rootModuleSymbol.valueDeclaration.getSourceFile();
738732
const metadata = getDecoratorMetadata(
739-
sourceFile as Ts48MigrationAny,
733+
sourceFile,
740734
'NgModule',
741735
'@angular/core',
742736
) as ts.ObjectLiteralExpression[];
@@ -748,9 +742,9 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
748742

749743
const filePath = this.fileSystem.resolve(sourceFile.fileName);
750744
const recorder = this.fileSystem.edit(filePath);
751-
const providersField = getMetadataField(metadata[0] as Ts48MigrationAny, 'providers')[0];
745+
const providersField = getMetadataField(metadata[0], 'providers')[0];
752746
const providerIdentifiers = providersField
753-
? findMatchingChildNodes(providersField as Ts48MigrationAny, ts.isIdentifier)
747+
? findMatchingChildNodes(providersField, ts.isIdentifier)
754748
: null;
755749
const gestureConfigExpr = this._importManager.addImportToSourceFile(
756750
sourceFile,
@@ -781,7 +775,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
781775
) {
782776
const symbolName = this._printNode(newProviderNode, sourceFile);
783777
addSymbolToNgModuleMetadata(
784-
sourceFile as Ts48MigrationAny,
778+
sourceFile,
785779
sourceFile.fileName,
786780
'providers',
787781
symbolName,
@@ -834,17 +828,17 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
834828

835829
const sourceFile = rootModuleSymbol.valueDeclaration.getSourceFile();
836830
const metadata = getDecoratorMetadata(
837-
sourceFile as Ts48MigrationAny,
831+
sourceFile,
838832
'NgModule',
839833
'@angular/core',
840834
) as ts.ObjectLiteralExpression[];
841835
if (!metadata.length) {
842836
return;
843837
}
844838

845-
const importsField = getMetadataField(metadata[0] as Ts48MigrationAny, 'imports')[0];
839+
const importsField = getMetadataField(metadata[0], 'imports')[0];
846840
const importIdentifiers = importsField
847-
? findMatchingChildNodes(importsField as Ts48MigrationAny, ts.isIdentifier)
841+
? findMatchingChildNodes(importsField, ts.isIdentifier)
848842
: null;
849843
const recorder = this.fileSystem.edit(this.fileSystem.resolve(sourceFile.fileName));
850844
const hammerModuleExpr = this._importManager.addImportToSourceFile(
@@ -861,7 +855,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
861855
) {
862856
const symbolName = this._printNode(hammerModuleExpr, sourceFile);
863857
addSymbolToNgModuleMetadata(
864-
sourceFile as Ts48MigrationAny,
858+
sourceFile,
865859
sourceFile.fileName,
866860
'imports',
867861
symbolName,

0 commit comments

Comments
 (0)