mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 20:37:00 -05:00
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:
committed by
GitHub
parent
43bf039a94
commit
cdfa63aa40
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user