Fix exported type resolution in commonjs (#24495)

* Fix resolution of exported types in commonjs

It is fine to resolve the types of exported classes in ES6:

```js
export class C {
}
var c = new C()
```

But not for commonjs exported classes:

```js
module.exports.C = class {
}
var c = new C() // should error
```

Fixes #24492

* All jsdoc type aliases are available locally in commonjs modules

* Check that location isSourceFile before commonJsModuleIndicator
This commit is contained in:
Nathan Shively-Sanders
2018-05-30 14:12:38 -07:00
committed by GitHub
parent 43bf039a94
commit cdfa63aa40
8 changed files with 52 additions and 13 deletions

View File

@@ -1323,8 +1323,14 @@ namespace ts {
}
}
// ES6 exports are also visible locally (except for 'default'), but commonjs exports are not (except typedefs)
if (name !== InternalSymbolName.Default && (result = lookup(moduleExports, name, meaning & SymbolFlags.ModuleMember))) {
break loop;
if (isSourceFile(location) && location.commonJsModuleIndicator && !result.declarations.some(isJSDocTypeAlias)) {
result = undefined;
}
else {
break loop;
}
}
break;
case SyntaxKind.EnumDeclaration: