---
title: "SW12001: Incompatible declaration assignment"
description: "A variable that holds one ref or animation is assigned a different one."
image: "https://stillwind.dev/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://stillwind.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SW12001: Incompatible declaration assignment

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

```ts
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

```ts
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.

Source: https://stillwind.dev/docs/errors/SW12001/index.mdx
