diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 31d47473b6c4e..5b107cb53c871 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3882,7 +3882,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function resolveExportByName(moduleSymbol: Symbol, name: __String, sourceNode: TypeOnlyCompatibleAliasDeclaration | undefined, dontResolveAlias: boolean) { const exportValue = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals); - const exportSymbol = exportValue ? getPropertyOfType(getTypeOfSymbol(exportValue), name) : moduleSymbol.exports!.get(name); + const exportSymbol = exportValue + ? getPropertyOfType(getTypeOfSymbol(exportValue), name, /*skipObjectFunctionPropertyAugment*/ true) + : moduleSymbol.exports!.get(name); const resolved = resolveSymbol(exportSymbol, dontResolveAlias); markSymbolOfAliasDeclarationIfTypeOnly(sourceNode, exportSymbol, resolved, /*overwriteEmpty*/ false); return resolved; diff --git a/tests/baselines/reference/crashDeclareGlobalTypeofExport.symbols b/tests/baselines/reference/crashDeclareGlobalTypeofExport.symbols new file mode 100644 index 0000000000000..fe693aa435361 --- /dev/null +++ b/tests/baselines/reference/crashDeclareGlobalTypeofExport.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/bar.d.ts === +import * as foo from './foo' +>foo : Symbol(foo, Decl(bar.d.ts, 0, 6)) + +export as namespace foo +>foo : Symbol(foo, Decl(bar.d.ts, 0, 28)) + +export = foo; +>foo : Symbol(foo, Decl(bar.d.ts, 0, 6)) + +declare global { +>global : Symbol(global, Decl(bar.d.ts, 2, 13)) + + const foo: typeof foo; +>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9)) +>foo : Symbol(foo, Decl(foo.d.ts, 7, 13), Decl(bar.d.ts, 5, 9)) +} + +=== tests/cases/compiler/foo.d.ts === +interface Root { +>Root : Symbol(Root, Decl(foo.d.ts, 0, 0)) + + /** + * A .default property for ES6 default import compatibility + */ + default: Root; +>default : Symbol(Root.default, Decl(foo.d.ts, 0, 16)) +>Root : Symbol(Root, Decl(foo.d.ts, 0, 0)) +} + +declare const root: Root; +>root : Symbol(root, Decl(foo.d.ts, 7, 13)) +>Root : Symbol(Root, Decl(foo.d.ts, 0, 0)) + +export = root; +>root : Symbol(root, Decl(foo.d.ts, 7, 13)) + diff --git a/tests/baselines/reference/crashDeclareGlobalTypeofExport.types b/tests/baselines/reference/crashDeclareGlobalTypeofExport.types new file mode 100644 index 0000000000000..31a78acd23eeb --- /dev/null +++ b/tests/baselines/reference/crashDeclareGlobalTypeofExport.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/bar.d.ts === +import * as foo from './foo' +>foo : { default: Root; } + +export as namespace foo +>foo : { default: Root; } + +export = foo; +>foo : { default: Root; } + +declare global { +>global : typeof global + + const foo: typeof foo; +>foo : Root +>foo : Root +} + +=== tests/cases/compiler/foo.d.ts === +interface Root { + /** + * A .default property for ES6 default import compatibility + */ + default: Root; +>default : Root +} + +declare const root: Root; +>root : Root + +export = root; +>root : Root + diff --git a/tests/cases/compiler/crashDeclareGlobalTypeofExport.ts b/tests/cases/compiler/crashDeclareGlobalTypeofExport.ts new file mode 100644 index 0000000000000..ffdbebf89a710 --- /dev/null +++ b/tests/cases/compiler/crashDeclareGlobalTypeofExport.ts @@ -0,0 +1,21 @@ +// @esModuleInterop: true + +// @Filename: bar.d.ts +import * as foo from './foo' +export as namespace foo +export = foo; + +declare global { + const foo: typeof foo; +} + +// @Filename: foo.d.ts +interface Root { + /** + * A .default property for ES6 default import compatibility + */ + default: Root; +} + +declare const root: Root; +export = root; diff --git a/tests/cases/fourslash/codefixCrashExportGlobal.ts b/tests/cases/fourslash/codefixCrashExportGlobal.ts new file mode 100644 index 0000000000000..83e5aed616fd2 --- /dev/null +++ b/tests/cases/fourslash/codefixCrashExportGlobal.ts @@ -0,0 +1,26 @@ +/// + +// @Filename: bar.ts +//// import * as foo from './foo' +//// export as namespace foo +//// export = foo; +//// +//// declare global { +//// const foo: typeof foo; +//// } + +// @Filename: foo.d.ts +//// interface Root { +//// /** +//// * A .default property for ES6 default import compatibility +//// */ +//// default: Root; +//// } +//// +//// declare const root: Root; +//// export = root; + +goTo.file("bar.ts"); +verify.not.codeFixAvailable(); +goTo.file("foo.d.ts"); +verify.not.codeFixAvailable();