Javascript Messages API Error 1- I tried to set an error message in Drupal 8 from javascript with the new Messages API using the following code:

const messages = new Drupal.Message();
messages.add('test message');


I get the following error on the console log:

drupal.js?v=8.8.5:13 Uncaught TypeError: Drupal.Message is not a constructor.

How can I include this API?

2- As I can see in message.es6.js, there is an option to set message type: error, warning and status. How to pass these params once I get the function working?

Reference Documentation: https://www.drupal.org/node/2930536

Thank you.
You need to make sure your library declares a dependency on core/drupal.message, e.g.

foo:
  js:
    js/foo.js: {}
  dependencies:
    - core/drupal.message


Once you've done that, you can choose the message type by including options:

const messages = new Drupal.Message();
messages.add('test message', { type: 'status' });