Microsoft/TypeScript
GitHub ã§èŠãJSDoc `@template` generic with promise not resolved with CommonJS Export
Open
#42,283 opened on 2021幎1æ11æ¥
BugDomain: JSDocHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
JSDoc, CommonJS, ESM, ES Modules, @template, generics, module.exports, promises
ð Version & Regression Information
- This is the behavior in every version I tried (and I also tried
typescript@next, and I reviewed the FAQ for entries about this
⯠Playground Link
I guess the Playground doesn't support multiple files, which this bug is based on.
A minimal repro can be found in the Code section below (based on this repo).
ð» Code
This is based on this repo: https://github.com/karlhorky/ts-jsdoc-template-promise-commonjs-bug
// main.js
const promiseWrapperCjs = require('./promise-wrapper-cjs');
const { default: promiseWrapperEsm } = require('./promise-wrapper-esm');
const resultCjs = promiseWrapperCjs(Promise.resolve(1)); // â Promise<{data: T}>
const resultEsm = promiseWrapperEsm(Promise.resolve(1)); // â
Promise<{data: number}>
// promise-wrapper-cjs.js
/**
* @function
* @template T
* @param {Promise<T>} promise
* @returns {Promise<{data: T}>}
*/
module.exports = function promiseWrapper(promise) {
return promise.then((data) => ({
data,
}));
};
// promise-wrapper-esm.js
/**
* @function
* @template T
* @param {Promise<T>} promise
* @returns {Promise<{data: T}>}
*/
export default function promiseWrapper(promise) {
return promise.then((data) => ({
data,
}));
}
ð Actual behavior
Generic type not resolved in CommonJS version, but ES Module version works
ð Expected behavior
Generic type resolved in both CommonJS and ES Module versions