This repository was archived by the owner on Jan 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 59
Inference from pattern matching #344
Copy link
Copy link
Open
Labels
questionFurther information is requestedFurther information is requested
Description
Would it possible (and would it make sense) to add inference for pattern matching?
For example:
function update(state, action) {
switch (action.type) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
default:
return state;
}
}
let nextState = update(0, { type: "INCREMENT" });Here, it's clear from reading the code that action.type has a defined set of expected values.
Hegel does infer from usage that action must have a type property.
But it does not infer that the type is a string - although it's clear to a person familiar with pattern matching that, not only is a string property expected, but there is also an expected set of constant string types.
I'm sure this is non-trivial, but I'm wondering if it's even possible and whether it would make sense? 🙂
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested