Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.

Inference from pattern matching #344

@mindplay-dk

Description

@mindplay-dk

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

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions