The Wayback Machine - https://web.archive.org/web/20220720165134/https://github.com/microsoft/TypeScript/issues/49869
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

No error in JavaScript on optional binding pattern parameter #49869

Open
jespertheend opened this issue Jul 12, 2022 · 3 comments
Open

No error in JavaScript on optional binding pattern parameter #49869

jespertheend opened this issue Jul 12, 2022 · 3 comments
Assignees
Labels
Bug Good First Issue

Comments

@jespertheend
Copy link

@jespertheend jespertheend commented Jul 12, 2022

Bug Report

πŸ”Ž Search Terms

TS2463 javascript

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about default

⏯ Playground Link

πŸ’» Code

/**
 * @typedef Options
 * @property {string} maybeUndefined
 */

/**
 * @param {Options} [options]
 */
function test({
	maybeUndefined = "str",
}) {
	takesString(maybeUndefined);
}

/**
 * @param {string} str
 */
function takesString(str) {
	console.log(str);
}

test();

πŸ™ Actual behavior

No error is thrown.

πŸ™‚ Expected behavior

An error is thrown similar to what happens in the TypeScript equivalent of this code. Note that in the playground link I have checked all options that are supposed to make types more strict. Also note that when this code is run, you'll end up with a runtime error. The same is true for the TypeScript equivalent, but in that case you get an error in advance warning you that the code you wrote will cause issues.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation label Jul 12, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.9.0 milestone Jul 12, 2022
@sandersn sandersn added Working as Intended and removed Needs Investigation labels Jul 19, 2022
@sandersn
Copy link
Member

@sandersn sandersn commented Jul 19, 2022

@param {Options} [options] declares the parameter as optional. The equivalent in typescript is { maybeUndefined = 'str' }?: options, which also gets rid of the error. (Although it adds an error at the declaration site since this combination isn't legal -- and should probably be illegal in javascript too.)

Instead, use @param {Options} options

@jespertheend
Copy link
Author

@jespertheend jespertheend commented Jul 20, 2022

Thanks for looking into this @sandersn!
I'm not really sure why this got closed as working as intended, since you mentioned

and should probably be illegal in javascript too.

Should I create a feature request / new issue for this?

@sandersn sandersn changed the title No TS2463 in JavaScript for optional parameters in an options object. No error in JavaScript on optional binding pattern parameter Jul 20, 2022
@sandersn
Copy link
Member

@sandersn sandersn commented Jul 20, 2022

Oh, I misread the whole thing. I'll re-open.

@sandersn sandersn reopened this Jul 20, 2022
@sandersn sandersn added Bug Good First Issue and removed Working as Intended labels Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good First Issue
Projects
None yet
Development

No branches or pull requests

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.