TS: Add workaround for 'globalThis' getProperties() crash

This commit is contained in:
Asger F
2019-04-30 10:56:02 +01:00
parent 686d72c356
commit 5c8dd7eedd
5 changed files with 37 additions and 1 deletions

View File

@@ -819,8 +819,24 @@ export class TypeTable {
this.isInShallowTypeContext = false;
}
/**
* Returns the properties of the given type, or `null` if the properties of this
* type could not be computed.
*/
private tryGetProperties(type: ts.Type) {
// Workaround for https://github.com/Microsoft/TypeScript/issues/30845
// Should be safe to remove once that has been fixed.
try {
return type.getProperties();
} catch (e) {
return null;
}
}
private extractProperties(type: ts.Type, id: number) {
for (let symbol of type.getProperties()) {
let props = this.tryGetProperties(type);
if (props == null) return;
for (let symbol of props) {
let propertyType = this.typeChecker.getTypeOfSymbolAtLocation(symbol, this.arbitraryAstNode);
if (propertyType == null) continue;
let propertyTypeId = this.getId(propertyType);

View File

@@ -0,0 +1,3 @@
import javascript
select "Success"

View File

@@ -0,0 +1,3 @@
{
"include": ["."]
}

View File

@@ -0,0 +1,13 @@
'use strict';
var _myGlobal = this;
module Test {
var global = _myGlobal || {};
export class C {}
export function f(x: C) {
global.field = x || {};
}
}