-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Milestone
Description
TypeScript Version: 3.3.3
Search Terms: import, typedef, callback jsCheck
I have an issue with importing generic function type declared with @callback in another file.
Here is example:
In file1.js I've defined generic function with template parameter
// file1.js
/**
* @template T
* @template {Error} E
* @callback CallbackWithResult
* @param {E|null} error
* @param {T} [result]
*/And in another file I've imported that declaration
// file2.js
/** @typedef {import('./file1').CallbackWithResult} CallbackWithResult */
/**
* @param {CallbackWithResult<number>} callback
*/
function doSomething(callback) {
callback(null, 42);
}Attempting to check file2.js gives following errors
file2.js:4:15 - error TS2314: Generic type 'CallbackWithResult' requires 2 type argument(s).
4 /** @typedef {import('./file1').CallbackWithResult} CallbackWithResult */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
file2.js:7:12 - error TS2315: Type 'CallbackWithResult' is not generic.
7 * @param {CallbackWithResult<number>} callback
~~~~~~~~~~~~~~~~~~~~~~~~~~Question is: how to properly import generic declarations without defining another set of template variables?