Skip to content

Suggestion: error when immediate function expression which returns a value is assigned to function type with void return type #19014

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
NaridaL opened this issue Oct 7, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@NaridaL
Copy link
Contributor

NaridaL commented Oct 7, 2017

This would be the analog of the error for additional properties in object literals for function return values.

TypeScript Version: 2.5.3 / nightly (2.6.0-dev.20171007)

Code

declare function voidCallback(cb: () => void)

// actual: no error
// expected: error: callback ignores return value 
voidCallback(() => 23)

const f = () => 45

// should still work:
voidCallback(f)

voidCallback(() => {
    // should still be allowed for flow control
    return
})
@mhegazy
Copy link
Contributor

mhegazy commented Oct 9, 2017

seems like a duplicate of #8240 and #8584

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 9, 2017
@NaridaL
Copy link
Contributor Author

NaridaL commented Oct 9, 2017

Yeah they are similar, but if I'm not mistaken in this case returning a value is definitely useless (like for object literals) while those are describing more general cases of not using return values.

@RyanCavanaugh
Copy link
Member

Consider if you had written voidCallback(() => arr.push(10)), which does return a value but is not wrong.

@NaridaL
Copy link
Contributor Author

NaridaL commented Oct 9, 2017

True, you'd have to write () => { arr.push(10) }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants