Skip to content

warn

ts
warn(
  code: ToolkitDiagnosticCode,
  message: string,
  context?: { component?: string; target?: Element },
): CustomEvent<ToolkitDiagnosticDetail>

Reports a warning on the diagnostic channel. A warning carries no error value — that is the difference from reportDiagnostic(), and it is a union in the type rather than an optional field.

Usage

ts
import { 
warn
} from '@studiometa/js-toolkit';
warn
('carousel.no-slides', 'A Carousel with no slide does nothing. Add `data-component="Slide"`.', {
component
: 'Carousel',
});

Return value

  • the dispatched event, so a caller can read defaultPrevented.

What happens

  1. The event is dispatched — always before any output.
  2. If nothing cancelled it, console.warn() is called once, with exactly [js-toolkit:<code>] <message>:
[js-toolkit:option.literal-default] Panel: the `tween` option default must be a factory function.

That exact format is what makes the console output greppable and what lets a listener reproduce it.

From a component

$warn(code, message) fills the component name in:

js
this.$warn('carousel.no-slides', 'A Carousel with no slide does nothing.');

Deduplication

Core's own warnings are deduplicated by weak owner plus a misuse key, in a revisioned shared-runtime slot — so a misuse is reported once per instance, per element or per declaration, and it works across independently evaluated copies of the package without retaining instances, elements, declarations, runners or manifest inputs.

The public warn() does not deduplicate. Call it where the condition is detected once.

Write a message that says what to do

The framework's own messages name the component, the thing that is wrong and the correction — option.literal-default names the option and the factory form to write instead. A warning a reader cannot act on is noise on a channel meant for monitoring.

MIT Licensed