TypeScript/tests/cases/conformance/jsdoc/typedefCrossModule2.ts
Nathan Shively-Sanders 7cda045d52
Always export typedefs (#23723)
* Always export typedefs

This actually just required deleting a check in declareModuleMembers
and checking for external AND commonjs modules in a couple of places.

However, while experimenting with this feature, I discovered that even
previously-exported typedefs would only be exported if they came after a
commonjs export node. So I added a commonjs check to the pass in the
parser. It will not catch nested module.exports, but it will catch
top-level assignments.

The new test tests both changes.

* Post-bind typedef instead of pre-checking for commonjs

* Duplicate identifier errors

* Fix class type reference resolution+update baselines

* Move to a type-based check for duplicate identifiers
2018-04-30 14:55:26 -07:00

40 lines
591 B
TypeScript

// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: mod1.js
// error
/** @typedef {number} Foo */
class Foo { } // should error
/** @typedef {number} Bar */
exports.Bar = class { }
/** @typedef {number} Baz */
module.exports = {
Baz: class { }
}
// ok
/** @typedef {number} Qux */
var Qux = 2;
/** @typedef {number} Quid */
exports.Quid = 2;
/** @typedef {number} Quack */
module.exports = {
Quack: 2
}
// @Filename: use.js
var mod = require('./mod1.js');
/** @type {import("./mod1.js").Baz} */
var b;
/** @type {mod.Baz} */
var bb;
var bbb = new mod.Baz();