Skip to content

    ↑↓ move · ⏎ open · esc close

    TS2322

    Not assignable

    Type 'number' is not assignable to type 'string'.

    The compiler’s own words. Not translated — this is the string you pasted into a search box.

    The most common error TypeScript has. A value of one type was put where another was required, and the two are not compatible in that direction.

    Reproduction

    const value: string = 1

    The build asserts this emits exactly this code.

    Why the compiler says this

    Assignability has a direction, and the message always reads source-then-target. That order is the whole diagnostic: `number` is not assignable to `string` says nothing about whether the reverse would work. When the message surprises you, it is usually because you read it as a statement about equality — it is not, it is a statement about one-way substitution, and half of TypeScript follows from that distinction.

    Fixes

    1. 01
      const value: string = String(1)

      Convert the value, if a conversion is what you meant. This is the honest fix and the one that survives review.

    2. 02
      const value: string | number = 1

      Or widen the target, if it genuinely holds both. A union says the variable really can be either, which is a different claim from a cast and a much safer one.

    Takeaway

    Read the message as an arrow, not an equals sign. Source on the left, target on the right, and the question is always whether the left can stand in for the right.

    Where to go next

    Errors