TypeScript/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.types
Nathan Shively-Sanders aba932aefa
Create synthetic exports symbol for commonjs module (#42655)
* Commonjs module:create synthetic exports symbol

Previously, the `module` identifier in commonjs modules got a synthetic
type with a single property `exports`. The exports property reused the
file's symbol, which, for a module file, gives the correct exported
properties.

However, the name of this symbol was still the filename of the file, not
`exports`. This PR creates a synthetic symbol for `exports` by copying
in a similar way to esModuleInterop's `default` symbol in
`resolveESModuleSymbol` (although the intent there is to strip off
signatures from the symbol).

* correct parent of synthetic symbol
2021-02-05 10:56:03 -08:00

88 lines
2.3 KiB
Plaintext

=== tests/cases/conformance/jsdoc/declarations/file2.js ===
const {myTypes} = require('./file.js');
>myTypes : { [x: string]: any; }
>require('./file.js') : typeof import("tests/cases/conformance/jsdoc/declarations/file")
>require : any
>'./file.js' : "./file.js"
/**
* @namespace testFnTypes
* @global
* @type {Object<string,*>}
*/
const testFnTypes = {
>testFnTypes : { [x: string]: any; }
>{ // SOME PROPS HERE} : {}
// SOME PROPS HERE
};
/** @typedef {boolean|myTypes.typeC} testFnTypes.input */
/**
* @function testFn
* @description A test function.
* @param {testFnTypes.input} input - Input.
* @returns {number|null} Result.
*/
function testFn(input) {
>testFn : (input: testFnTypes.input) => number | null
>input : boolean | myTypes.typeC
if (typeof input === 'number') {
>typeof input === 'number' : boolean
>typeof input : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>input : boolean | myTypes.typeC
>'number' : "number"
return 2 * input;
>2 * input : number
>2 : 2
>input : never
} else {
return null;
>null : null
}
}
module.exports = {testFn, testFnTypes};
>module.exports = {testFn, testFnTypes} : typeof module.exports
>module.exports : typeof module.exports
>module : { exports: typeof module.exports; }
>exports : typeof module.exports
>{testFn, testFnTypes} : { testFn: (input: testFnTypes.input) => number; testFnTypes: { [x: string]: any; }; }
>testFn : (input: testFnTypes.input) => number
>testFnTypes : { [x: string]: any; }
=== tests/cases/conformance/jsdoc/declarations/file.js ===
/**
* @namespace myTypes
* @global
* @type {Object<string,*>}
*/
const myTypes = {
>myTypes : { [x: string]: any; }
>{ // SOME PROPS HERE} : {}
// SOME PROPS HERE
};
/** @typedef {string|RegExp|Array<string|RegExp>} myTypes.typeA */
/**
* @typedef myTypes.typeB
* @property {myTypes.typeA} prop1 - Prop 1.
* @property {string} prop2 - Prop 2.
*/
/** @typedef {myTypes.typeB|Function} myTypes.typeC */
exports.myTypes = myTypes;
>exports.myTypes = myTypes : { [x: string]: any; }
>exports.myTypes : { [x: string]: any; }
>exports : typeof import("tests/cases/conformance/jsdoc/declarations/file")
>myTypes : { [x: string]: any; }
>myTypes : { [x: string]: any; }