Skip to content

arguments detection for jsdoc / javascript has a false positive #47004

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

Closed
Raynos opened this issue Dec 3, 2021 · 3 comments · Fixed by #47054
Closed

arguments detection for jsdoc / javascript has a false positive #47004

Raynos opened this issue Dec 3, 2021 · 3 comments · Fixed by #47054
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@Raynos
Copy link

Raynos commented Dec 3, 2021

Typescript infers that if you touch the arguments value inside a function that it has extra arguments as ...args: any[]

However if you call a method with an object and one of the fields is called arguments: [] then it thinks you are using the arguments variable inside of the function, then it adds ...args: any[]

image

https://www.typescriptlang.org/play?filetype=js#code/LAKAxg9gdgzgLgAhgT3gUwLYILwIN5JpQAmAFBAJT4C+C1ooAZhBAEYCGATqQOTRo8KAbgYgA9ACoJoBBIQABAA5d2WPPE4BLKAHNa-GRLFMArlDBxN0BMzZcE5KGip4ZSVHEwA6GETKuQBCCEdkVNAC4EHlsOTh4AGjcgrh0TDCI4GEiAbR4ACzQAG0KIHgBdN2oKUGogA

const system = { send(o) {} }

foobar('one');

/**
 * @param {string} one
 */
function foobar (one) {
  system.send({
    api: 'foobar',
    arguments: ['hello']
  })
}
@jimmywarting
Copy link
Contributor

jimmywarting commented Dec 16, 2021

I have a similar problem

but i'm actually using arguments.length to just simply validating/asserting if the number of arguments is correct at runtime. This only occur in .js (not in .ts)

javascript:


typescript:

I think the better option would be to not add ...args[]: any at all if you use arguments...
the new normal is that you instead use spread when you actually mean to support any number of arguments

class Math {
  /** @param {number} args */
  min (...args) { 
  }
}

using spread is actually better cuz then you can also type it with jsdoc

or just use: @param {...number} var_args if you actually want to use arguments for something

@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Dec 16, 2021
@jimmywarting
Copy link
Contributor

if i want to use arguments but do not want to have ...args[]: any then what can I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants