-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Function parameters are not inferable when defined via JSDoc using @type tag (with strict) #58580
Comments
Funny behaviour, and why does it work somewhat better in only one file: Playground function func(/** @type {string} */ param) {}
/**
* @typedef {typeof func} Func
* @typedef {Func extends (...args: infer P) => any ? P : never} FuncParam
*/ Result: |
@kungfooman That's because the parameter itself is, in fact, optional: function func(/** @type {string} */ param) {}
/**
* @typedef {typeof func} Func
* @typedef {Func extends (...args: infer P) => any ? P : never} FuncParam
*/
func(); // not an error I don't know why it's treated as optional, but the inference result is correct. |
If we turn on IMO it should only ever be considered optional if we use the Google Closure syntax: function func(/** @type {string=} */ param) {} ( |
Thank you for the playground links! Reproduces the problem nicely. In the non-optional cases above, the tooltip hover still thinks that In addition, both the /** @param {string} param */
function func(param) {}
func() // error and |
The generated function has Currently, this flag is not assigned to signatures coming from JS files when the function has either /** @satisfies {(arg: string) => void} */
const func = function func(param) { };
func() // oops Related(ish) case to the |
🔎 Search Terms
infer
@type
strict
JSDoc
Parameters
Function
🕗 Version & Regression Information
I've pulled the latest version of this repository and made a test case in the "fourslash" section, which demonstrates the problem I see.
(I couldn't see how to do something like this in the playground, sorry. Commit is linked)
⏯ Playground Link
scottmcginness@cda5366
💻 Code
In tsconfig.json:
(The above definition is obviously just
Parameters<T>
, but put in full for comparison with another example below)🙁 Actual behavior
The type
FuncParam
resolved tonever
(i.e. it took the false branch of the ternary)🙂 Expected behavior
The type
FuncParam
should be[param: string]
, as given by the JSDoc@type
tagAdditional information about the issue
This seems like a bug because all other ways of specifying the
func
function with JSDoc or theFuncParam
type seemed to work as expected:@param
tag instead:yields
FuncParam
→[param: string]
undefined
works, but is not what I want for the definition offunc
:yields
FuncParam
→[param?: string | undefined]
infer
works (but is not usable for the intended purpose):Parameters<T>
works):This also only seemed to occur specifically with
strict: true
. I couldn't see this with any of the otherstrict...
options (though I may have missed something here)All other views on the function seems to show that it is happily a function with a string parameter. i.e. the tooltip hover over
func
, while insideuse-it.ts
shows:The output I see from the single test linked above (using
hereby runtests --tests=jsDocInferredFunctionParameters
) is:This also happens for arrow functions and class methods, e.g.
with similar code as for
FuncParam
.The text was updated successfully, but these errors were encountered: