Skip to content

Commit

Permalink
Migrate to TypeScript 3.7.2.
Browse files Browse the repository at this point in the history
In TypeScript 3.7, `TypeReference` objects never have a `typeArguments`
property. See microsoft/TypeScript#33693 for
some context.

The adjustment to the tests actually fixes a long standing issue with
the emit.
  • Loading branch information
mprobst committed Jan 7, 2020
1 parent b9bcf99 commit a1e7cce
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -11,7 +11,7 @@
"src/*"
],
"peerDependencies": {
"typescript": "~3.6.4"
"typescript": "~3.7.2"
},
"devDependencies": {
"@bazel/bazel": "^0.29.0",
Expand All @@ -30,7 +30,7 @@
"source-map": "^0.7.3",
"source-map-support": "^0.5.6",
"tslint": "5.11.0",
"typescript": "3.6.4"
"typescript": "3.7.2"
},
"scripts": {
"build": "bazel build //:npm_package",
Expand Down
5 changes: 3 additions & 2 deletions src/module_type_translator.ts
Expand Up @@ -368,10 +368,11 @@ export class ModuleTypeTranslator {
if ((type.flags & ts.TypeFlags.Object) !== 0 &&
(type as ts.ObjectType).objectFlags & ts.ObjectFlags.Reference) {
const typeRef = type as ts.TypeReference;
if (!typeRef.typeArguments) {
const typeArgs = this.typeChecker.getTypeArguments(typeRef);
if (!typeArgs) {
throw new Error('rest parameter does not resolve to a reference type');
}
newTag.type = this.typeToClosure(fnDecl, typeRef.typeArguments![0]);
newTag.type = this.typeToClosure(fnDecl, typeArgs[0]);
return;
}
// If we fail to unwrap the Array<> type, emit an unknown type.
Expand Down
11 changes: 6 additions & 5 deletions src/type_translator.ts
Expand Up @@ -620,8 +620,9 @@ export class TypeTranslator {
// Translate can return '?' for a number of situations, e.g. type/value conflicts.
// `?<?>` is illegal syntax in Closure Compiler, so just return `?` here.
if (typeStr === '?') return '?';
if (referenceType.typeArguments) {
const params = referenceType.typeArguments.map(t => this.translate(t));
const typeArgs = this.typeChecker.getTypeArguments(referenceType);
if (typeArgs) {
const params = typeArgs.map(t => this.translate(t));
typeStr += `<${params.join(', ')}>`;
}
return typeStr;
Expand Down Expand Up @@ -852,14 +853,14 @@ export class TypeTranslator {
paramTypes.push('!Array<?>');
continue;
}
const typeRef = paramType as ts.TypeReference;
if (!typeRef.typeArguments) {
const typeArgs = this.typeChecker.getTypeArguments(paramType as ts.TypeReference);
if (typeArgs.length === 0) {
// When a rest argument resolves empty, i.e. the concrete instantiation does not take any
// arguments, the type arguments are empty. Emit a function type that takes no arg in this
// position then.
continue;
}
paramType = typeRef.typeArguments[0];
paramType = typeArgs[0];
}
let typeStr = this.translate(paramType);
if (varArgs) typeStr = '...' + typeStr;
Expand Down
2 changes: 1 addition & 1 deletion test_files/augment/externs.js
Expand Up @@ -6,7 +6,7 @@
// externs from test_files/augment/angular/index.d.ts:
/** @const */
var test_files$augment$angular$index_ = {};
/** @type {!IAngularStatic} */
/** @type {!test_files$augment$angular$index.angular.IAngularStatic} */
test_files$augment$angular$index_.angular;
/** @const */
test_files$augment$angular$index_.angular = {};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -1203,10 +1203,10 @@ tsutils@^2.27.2:
dependencies:
tslib "^1.8.1"

typescript@3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==
typescript@3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
integrity sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==

uglify-js@^3.1.4:
version "3.6.0"
Expand Down

0 comments on commit a1e7cce

Please sign in to comment.