Skip to content

    ↑↓ move · ⏎ open · esc close

    TS2345

    Wrong argument type

    Argument of type 'number' is not assignable to parameter of type 'string'.

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

    The same assignability failure as TS2322, at a call site. A separate code because the fix is almost always in a different place.

    Reproduction

    declare function take(value: string): void
    
    take(1)

    The build asserts this emits exactly this code.

    Why the compiler says this

    A parameter is a variable the function declares on your behalf, so passing an argument is an assignment and obeys the same rules. It gets its own code because the interesting question differs: with TS2322 you usually chose the wrong value, and with TS2345 you are usually calling something that expects a shape you have not built yet. The function has told you exactly what it wants, in the second half of the message.

    Fixes

    1. 01
      declare function take(value: string): void
      
      take('1')

      Pass what it asked for.

    2. 02
      declare function take(value: string | number): void
      
      take(1)

      Or change the signature, if the function should have accepted this all along. Worth doing only when you own the function and its body is genuinely safe for the wider type.

    Takeaway

    The second half of the message is a specification. Build that, rather than reaching for `as` to silence the first half.

    Errors