Skip to content

Commit 25924fa

Browse files
devversionmmalerba
authored andcommitted
refactor(multiple): ensure compatibility with TypeScript 4.3
Refactors code that fails with TypeScript 4.3. These changes are limited to the update migration as everything else remained compatible. This commit adds an integration test to ensure that the built NPM packages work with TypeScript 4.3.
1 parent a817f86 commit 25924fa

File tree

10 files changed

+31
-17
lines changed

10 files changed

+31
-17
lines changed

integration/ts-compat/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ write_file(
1313
# List of TypeScript packages that we want to run the compatibility test against.
1414
# The list contains NPM module names that resolve to the desired TypeScript version.
1515
typescript_version_packages = [
16+
"typescript-4.3",
1617
"typescript",
1718
]
1819

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"tslint": "^6.1.3",
224224
"tsutils": "^3.17.1",
225225
"typescript": "~4.2.3",
226+
"typescript-4.3": "npm:typescript@4.3.2",
226227
"vrsource-tslint-rules": "6.0.0",
227228
"yaml": "^1.10.0"
228229
},

scripts/caretaking/firebase-functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"firebase-functions": "^3.11.0"
1212
},
1313
"devDependencies": {
14-
"typescript": "^4.0.2",
14+
"typescript": "^4.3.2",
1515
"firebase-tools": "^8.6.0"
1616
},
1717
"private": true

scripts/caretaking/firebase-functions/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,10 +3794,10 @@ typedarray@^0.0.6:
37943794
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
37953795
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
37963796

3797-
typescript@^4.0.2:
3798-
version "4.0.3"
3799-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
3800-
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
3797+
typescript@^4.3.2:
3798+
version "4.3.2"
3799+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
3800+
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==
38013801

38023802
unique-string@^1.0.0:
38033803
version "1.0.0"

src/cdk/schematics/ng-update/migrations/constructor-signature.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ export class ConstructorSignatureMigration extends Migration<UpgradeData> {
9494
signature => getParameterTypesFromSignature(signature, this.typeChecker));
9595

9696
const expressionName = isNewExpression ? `new ${className}` : 'super';
97-
const signatures =
98-
classSignatures.map(signature => signature.map(t => this.typeChecker.typeToString(t)))
99-
.map(signature => `${expressionName}(${signature.join(', ')})`)
100-
.join(' or ');
97+
const signatures = classSignatures
98+
.map(signature =>
99+
signature.map(t => t === null ? 'any' : this.typeChecker.typeToString(t)))
100+
.map(signature => `${expressionName}(${signature.join(', ')})`)
101+
.join(' or ');
101102

102103
this.createFailureAtNode(
103104
node,
@@ -111,9 +112,9 @@ export class ConstructorSignatureMigration extends Migration<UpgradeData> {
111112

112113
/** Resolves the type for each parameter in the specified signature. */
113114
function getParameterTypesFromSignature(
114-
signature: ts.Signature, typeChecker: ts.TypeChecker): ts.Type[] {
115+
signature: ts.Signature, typeChecker: ts.TypeChecker): (ts.Type|null)[] {
115116
return signature.getParameters().map(
116-
param => typeChecker.getTypeAtLocation(param.declarations[0]));
117+
param => param.declarations ? typeChecker.getTypeAtLocation(param.declarations[0]) : null);
117118
}
118119

119120
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
648648
const mainFilePath = getProjectMainFile(project);
649649
const rootModuleSymbol = this._getRootModuleSymbol(mainFilePath);
650650

651-
if (rootModuleSymbol === null) {
651+
if (rootModuleSymbol === null || rootModuleSymbol.valueDeclaration === undefined) {
652652
this.failures.push({
653653
filePath: mainFilePath,
654654
message: `Could not setup Hammer gestures in module. Please ` +
@@ -726,7 +726,7 @@ export class HammerGesturesMigration extends DevkitMigration<null> {
726726
const mainFilePath = getProjectMainFile(project);
727727
const rootModuleSymbol = this._getRootModuleSymbol(mainFilePath);
728728

729-
if (rootModuleSymbol === null) {
729+
if (rootModuleSymbol === null || rootModuleSymbol.valueDeclaration === undefined) {
730730
this.failures.push({
731731
filePath: mainFilePath,
732732
message: `Could not setup HammerModule. Please manually set up the "HammerModule" ` +

src/material/schematics/ng-update/migrations/package-imports-v8/secondary-entry-points-migration.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function getDeclarationSymbolOfNode(node: ts.Node, checker: ts.TypeChecker): ts.
169169

170170

171171
/** Tries to resolve the name of the Material module that a node is imported from. */
172-
function resolveModuleName(node: ts.Identifier, typeChecker: ts.TypeChecker) {
172+
function resolveModuleName(node: ts.Identifier, typeChecker: ts.TypeChecker): string|null {
173173
// Get the symbol for the named binding element. Note that we cannot determine the
174174
// value declaration based on the type of the element as types are not necessarily
175175
// specific to a given secondary entry-point (e.g. exports with the type of "string")
@@ -186,7 +186,12 @@ function resolveModuleName(node: ts.Identifier, typeChecker: ts.TypeChecker) {
186186
// The filename for the source file of the node that contains the
187187
// first declaration of the symbol. All symbol declarations must be
188188
// part of a defining node, so parent can be asserted to be defined.
189-
const resolvedNode = symbol.valueDeclaration || symbol.declarations[0];
189+
const resolvedNode = symbol.valueDeclaration || symbol.declarations?.[0];
190+
191+
if (resolvedNode === undefined) {
192+
return null;
193+
}
194+
190195
const sourceFile = resolvedNode.getSourceFile().fileName;
191196

192197
// File the module the symbol belongs to from a regex match of the

tools/tslint-rules/coercionTypesRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Walker extends Lint.RuleWalker {
128128
}
129129

130130
const symbol = this._typeChecker.getTypeAtLocation(baseType).getSymbol();
131-
currentClass = symbol && ts.isClassDeclaration(symbol.valueDeclaration) ?
131+
currentClass = symbol?.valueDeclaration && ts.isClassDeclaration(symbol.valueDeclaration) ?
132132
symbol.valueDeclaration : null;
133133

134134
if (currentClass) {

tools/tslint-rules/noUndecoratedBaseClassDiRule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class Walker extends Lint.RuleWalker {
7272
return null;
7373
}
7474
const symbol = this._typeChecker.getTypeAtLocation(baseTypes[0]).getSymbol();
75-
if (!symbol || !ts.isClassDeclaration(symbol.valueDeclaration)) {
75+
if (symbol?.valueDeclaration === undefined ||
76+
!ts.isClassDeclaration(symbol.valueDeclaration)) {
7677
return null;
7778
}
7879
if (this.hasExplicitConstructor(symbol.valueDeclaration)) {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13760,6 +13760,11 @@ typedarray@^0.0.6:
1376013760
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1376113761
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1376213762

13763+
"typescript-4.3@npm:typescript@4.3.2":
13764+
version "4.3.2"
13765+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
13766+
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==
13767+
1376313768
typescript@4.2.3, typescript@^3.2.2, typescript@~4.2.3:
1376413769
version "4.2.3"
1376513770
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"

0 commit comments

Comments
 (0)