This error occurs when a variable that holds one ref, keyframes, or view transition definition is later assigned a different one. The compiler tracks which definitions a variable can hold, and the assignment breaks that record. The message includes the explanation from TypeScript.
Reported
let current = style.ref("card");
current = style.ref("panel");
style({ [current("hover")]: "underline" });SW12001: incompatible declaration identities: TS2322: Type 'StyleRef<string>' is not assignable to type 'StyleRef<"stillwind-identity/v1:eyJraW5kIjoicmVmIiwibW9kdWxlSWQiOiJSZWZlcmVuY2UudHN4Iiwic3RhcnQiOjQ2LCJlbmQiOjUzLCJiaW5kaW5nTmFtZSI6ImN1cnJlbnQifQ">'. Type 'string' is not assignable to type '"stillwind-identity/v1:eyJraW5kIjoicmVmIiwibW9kdWxlSWQiOiJSZWZlcmVuY2UudHN4Iiwic3RhcnQiOjQ2LCJlbmQiOjUzLCJiaW5kaW5nTmFtZSI6ImN1cnJlbnQifQ"'. Preserve declaration candidates with an explicit union or a generic parameter.
Source format: Jsx
Fixed
const card = style.ref("card");
const panel = style.ref("panel");
let current: typeof card | typeof panel = card;
current = panel;
style({ [current("hover")]: "underline" });How to fix
- Declare each definition in its own
const, and give the variable an explicit union of their types, as in the example. - In a function that accepts several definitions, use a generic parameter instead of a wider type.
- Keep the types that TypeScript infers when you pass definitions through exports.