diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c92c8bb97894d..396db42226bfb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1455,7 +1455,7 @@ namespace ts { if (!result) { if (lastLocation) { Debug.assert(lastLocation.kind === SyntaxKind.SourceFile); - if ((lastLocation as SourceFile).commonJsModuleIndicator && name === "exports") { + if ((lastLocation as SourceFile).commonJsModuleIndicator && name === "exports" && meaning & lastLocation.symbol.flags) { return lastLocation.symbol; } } diff --git a/tests/baselines/reference/jsdocTypeReferenceExports.errors.txt b/tests/baselines/reference/jsdocTypeReferenceExports.errors.txt new file mode 100644 index 0000000000000..48d0321be71d9 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceExports.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/jsdoc/bug27342.js(3,11): error TS2709: Cannot use namespace 'exports' as a type. + + +==== tests/cases/conformance/jsdoc/bug27342.js (1 errors) ==== + module.exports = {} + /** + * @type {exports} + ~~~~~~~ +!!! error TS2709: Cannot use namespace 'exports' as a type. + */ + var x + + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocTypeReferenceExports.symbols b/tests/baselines/reference/jsdocTypeReferenceExports.symbols new file mode 100644 index 0000000000000..0ae0a5e73a7e2 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceExports.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/jsdoc/bug27342.js === +module.exports = {} +>module.exports : Symbol("tests/cases/conformance/jsdoc/bug27342", Decl(bug27342.js, 0, 0)) +>module : Symbol(module, Decl(bug27342.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/bug27342", Decl(bug27342.js, 0, 0)) + +/** + * @type {exports} + */ +var x +>x : Symbol(x, Decl(bug27342.js, 4, 3)) + + diff --git a/tests/baselines/reference/jsdocTypeReferenceExports.types b/tests/baselines/reference/jsdocTypeReferenceExports.types new file mode 100644 index 0000000000000..843bb08f91b81 --- /dev/null +++ b/tests/baselines/reference/jsdocTypeReferenceExports.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/jsdoc/bug27342.js === +module.exports = {} +>module.exports = {} : typeof import("tests/cases/conformance/jsdoc/bug27342") +>module.exports : typeof import("tests/cases/conformance/jsdoc/bug27342") +>module : { "tests/cases/conformance/jsdoc/bug27342": typeof import("tests/cases/conformance/jsdoc/bug27342"); } +>exports : typeof import("tests/cases/conformance/jsdoc/bug27342") +>{} : {} + +/** + * @type {exports} + */ +var x +>x : typeof import("tests/cases/conformance/jsdoc/bug27342") + + diff --git a/tests/cases/conformance/jsdoc/jsdocTypeReferenceExports.ts b/tests/cases/conformance/jsdoc/jsdocTypeReferenceExports.ts new file mode 100644 index 0000000000000..e711ad4f58ffd --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocTypeReferenceExports.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @noEmit: true +// @checkJs: true +// @Filename: bug27342.js +module.exports = {} +/** + * @type {exports} + */ +var x +