Documentation / @finchart/core / index / styleSpec
Function: styleSpec()
styleSpec<
T>(spec):T
Defined in: packages/core/src/render/style-spec.ts:79
Declares a spec, checked against the style it produces, with its css names kept as literal types.
Two things have to hold at once and neither survives alone. satisfies StyleSpec<S> checks the shape but lets every property widen, so css lands as string and a name can never be read back out of the type — measured, and it is why a typo in a variable name was only ever caught by scraping the source. A const type parameter keeps the literals but checks nothing. Doing both, in that order, gives both.
export const CANDLE_STYLE_SPEC = /* @__PURE__ */ styleSpec({
up: { css: "--chart-candle-up", fallback: "#16a34a" },
}) satisfies StyleSpec<CandleSeriesStyle>;The satisfies stays outside the call. Checking there leaves T already inferred, so the names survive; threading the style type through the function instead needs a second call, and two calls cannot both carry the purity annotation the bundler needs.
/* @__PURE__ */ is not decoration. const X = { … } is inert and a bundler drops it unused; const X = f({ … }) is a call it must assume has effects, and every spec in the module is then retained. Measured without it: the one-series consumer went from 1.4 KB to 1.9 KB.
It returns the spec untouched — the whole function is the identity, and everything it does happens in the type system.
Type Parameters
T
T
Parameters
spec
T
Returns
T