Skip to content

Wrong report of TS2525 #26574

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
n9 opened this issue Aug 21, 2018 · 2 comments
Closed

Wrong report of TS2525 #26574

n9 opened this issue Aug 21, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@n9
Copy link

n9 commented Aug 21, 2018

TypeScript Version: 3.0.1 and also current @next 3.1.0-dev.20180821

Search Terms: TS2525

Code

interface Foo {
    b?: string
}

function bar1(arg?: Foo): void {
    const { b } = arg || {}
}

function bar2(arg?: Foo): void {
    const da = arg || {}
    const { b } = da
}

Expected behavior:
No error.

Actual behavior:
bar1 shows error: TS2525: Initializer provides no value for this binding element and the binding element has no default value.

Playground Link: https://www.typescriptlang.org/play/#src=interface%20Foo%20%7B%0D%0A%20%20%20%20b%3F%3A%20string%0D%0A%7D%0D%0A%0D%0Afunction%20bar1(arg%3F%3A%20Foo)%3A%20void%20%7B%0D%0A%20%20%20%20const%20%7B%20b%20%7D%20%3D%20arg%20%7C%7C%20%7B%7D%0D%0A%7D%0D%0A%0D%0Afunction%20bar2(arg%3F%3A%20Foo)%3A%20void%20%7B%0D%0A%20%20%20%20const%20da%20%3D%20arg%20%7C%7C%20%7B%7D%0D%0A%20%20%20%20const%20%7B%20b%20%7D%20%3D%20da%0D%0A%7D

Related Issues: no (only #21634)

@AlCalzone
Copy link
Contributor

Duplicate of #26235?

@n9
Copy link
Author

n9 commented Aug 21, 2018

@AlCalzone Yes, seems to.

@n9 n9 closed this as completed Aug 21, 2018
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants