-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Problem:
Funtional programming needs better support in TypeScript. Values are everything in FP and in TypeScript the expression statements just silently discard them. Not being able to track places where the values are discarded leads to severe bugs. Example:
// before refactoring
function notify(message: string) : void {
window.postMessage(message); // <-- assuming always works
}
// turns out that window.postMessage crashes when window gets closed
// need a check and a conditional result
// after refactoring
function notify(message: string) : Tried<void, 'cant-send-a-message'> {
if (window.closed) {
return failureFrom('cant-send-a-message');
} else {
return successFrom(window.postMessage(message));
}
}
// after such change we need to make sure that all places that call `notify` are addressed
// it's easy to overlook those without a help from a compilerWorkaround:
use a linter rule
Solution:
add a flag to the compiler
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created