validate() function

This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Ensure that the msg data model is _valid_, calling onError on errors.


export declare function validate(msg: Message, onError?: (type: MessageDataModelError['type'], node: MessageNode) => void): {
    functions: Set<string>;
    variables: Set<string>;


Parameter Type Description
msg Message  
onError (type: MessageDataModelError[‘type’], node: MessageNode) => void (Optional)


{ functions: Set<string>; variables: Set<string>; }

The sets of runtime functions and variables used by the message.


Detects the following errors:

  • **Variant Key Mismatch**: The number of keys on a _variant_ does not equal the number of _selectors_.

  • **Missing Fallback Variant**: The message does not include a _variant_ with only catch-all keys.

  • **Missing Selector Annotation**: A _selector_ does not have an _annotation_, or contains a _variable_ that does not directly or indirectly reference a _declaration_ with an _annotation_.

  • **Duplicate Declaration**: A _variable_ appears in two _declarations_.

  • **Invalid Forward Reference**: A _declaration_ _expression_ refers to a _variable_ defined by a later _declaration_.

  • **Duplicate Option Name**: The same _identifier_ appears as the name of more than one _option_ in the same _expression_.