Skip to content

    ↑↓ move · ⏎ open · esc close

    TS2344

    Does not satisfy the constraint

    Type 'number' does not satisfy the constraint 'string'.

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

    A type argument was rejected at the door. The generic said what it would accept, and this is not it.

    Reproduction

    type OnlyStrings<T extends string> = T
    
    type Bad = OnlyStrings<number>

    The build asserts this emits exactly this code.

    Why the compiler says this

    `extends` in a parameter list is not inheritance and not a hint — it is the argument check. `T extends string` means "whatever arrives must be assignable to `string`", and `number` is not. The error names the argument first and the constraint second, which is worth reading carefully: it is telling you which side you got wrong.

    Fixes

    1. 01
      type OnlyStrings<T extends string> = T
      
      type Good = OnlyStrings<'hello'>

      Pass something that fits. A string literal type is assignable to `string`, so it walks straight in.

    2. 02
      type Anything<T extends string | number> = T
      
      type AlsoGood = Anything<number>

      Or widen the constraint, if the generic genuinely can handle more than it claims. Widening because the error is annoying, rather than because the body is safe, just moves the failure inward.

    Takeaway

    The constraint is a contract the generic wrote about itself. Read the body before you loosen it — the constraint is usually load-bearing.

    Where to go next

    Errors