Interface TypeInferenceCollector

Collects an arbitrary number of inference rules and allows to infer a type for a given language node.

interface TypeInferenceCollector {
    addInferenceRule(rule: TypeInferenceRule, boundToType?: Type): void;
    addListener(listener: TypeInferenceCollectorListener): void;
    inferType(languageNode: unknown): Type | InferenceProblem[];
    removeInferenceRule(rule: TypeInferenceRule, boundToType?: Type): void;
    removeListener(listener: TypeInferenceCollectorListener): void;
}

Implemented by

Methods

  • Registers an inference rule. When inferring the type for a language node, all registered inference rules are checked until the first match.

    Parameters

    • rule: TypeInferenceRule

      a new inference rule

    • OptionalboundToType: Type

      an optional type, if the new inference rule is dedicated for exactly this type. If the given type is removed from the type system, this rule will be automatically removed as well.

    Returns void

  • Infers a type for the given language node.

    Parameters

    • languageNode: unknown

      the language node whose type shall be inferred

    Returns Type | InferenceProblem[]

    the found Type or some inference problems (might be empty), when none of the inference rules were able to infer a type