Skip to content

JSDoc @param and @returns types cannot access typeof other @params #43441

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

Open
andrewbranch opened this issue Mar 30, 2021 · 4 comments
Open
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation
Milestone

Comments

@andrewbranch
Copy link
Member

Bug Report

πŸ”Ž Search Terms

JSDoc param return typeof visibility

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

/**
 * @param {string | number | { x: number } | { y: 'hello' }} a
 * @param {typeof a | symbol[]} b
 * @returns {[typeof a, typeof b]}
 */
function makeTuple(a, b) {
    return [a, b];
}

πŸ™ Actual behavior

Cannot find name 'a' / 'b'

πŸ™‚ Expected behavior

Should work, the same way that it works in TS:

function makeTuple(a: string | number | { x: number } | { y: 'hello' }, b: typeof a): [typeof a, typeof b] {
    return [a, b];
}
@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation labels Mar 30, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Mar 30, 2021
@andrewbranch
Copy link
Member Author

/cc @sandersn to ensure this isn’t a duplicate / undesirable / impossible / previously discussed

@sandersn
Copy link
Member

It's new to me -- those TS types seem weird and undesirable to me, so it's likely that my JS semantics are just wrong compared to TS.

@andrewbranch
Copy link
Member Author

It’s a contrived example. The motivation is basically to avoid repeating verbose types if a later parameter or return type can be expressed in terms of a parameter type.

@awerlogus
Copy link

Related: #43403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation
Projects
None yet
Development

No branches or pull requests

3 participants