Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import generic function type declaration from one javascript file to another? #29964

Open
ArenSH opened this issue Feb 19, 2019 · 0 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@ArenSH
Copy link

ArenSH commented Feb 19, 2019

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?

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Mar 7, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants