-
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
how come () => void is a subtype of () => a if void isn't a subtype of a and a isn't subtype of void? #8581
Comments
tl;dr; the assumption is that it is safe to assign something that returns some value to something that returns see 3.11.3 Subtypes and Supertypes
|
it's not a safe assumption at all, ugh.... |
I have a function that returns a promise: |
anything that has to be serialized can't be passed round safely because there is a chance it will get swallowed by function sendMessageWhenReadyNoValuesIntended(doMyStuff: () => void) {
window.postMessage(JSON.stringify({ message: doMyStuff() }));
}
interface RandomCrazyObject {
self: RandomCrazyObject;
}
function processMyInput() : RandomCrazyObject {
let result = <RandomCrazyObject>{ };
result.self = result;
return result;
}
sendMessageWhenReadyNoValuesIntended(processMyInput()) |
The alternative is much worse -- imagine not being able to write this code: let arr = [1, 2];
// Error, can't convert 'number' return type to 'void'
[1, 2, 3].forEach(x => arr.push(x)); |
much worse, I agree, you sound more convincing than ever
|
If that's sarcasm I'm missing it 😛 |
not much sarcasm in 3 extra characters |
The text was updated successfully, but these errors were encountered: