Skip to content
TS7031

    ↑↓ move · ⏎ open · esc close

    TS7031

    Destructured value implicitly has any

    Binding element 'name' implicitly has an 'any' type.

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

    A destructuring pattern names a field, but the object containing that field has no known type.

    Reproduction

    function greet({ name }) {
      return name.toUpperCase()
    }

    The build asserts this emits exactly this code.

    Why the compiler says this

    The annotation belongs to the whole parameter pattern, not inside it. Until the container is typed, each extracted binding inherits the same missing information and becomes implicit `any`.

    Fixes

    1. 01
      function greet({ name }: { name: string }) {
        return name.toUpperCase()
      }

      Annotate the object pattern directly for a small one-off shape.

    2. 02
      type Person = { name: string }
      
      function greet({ name }: Person) {
        return name.toUpperCase()
      }

      Name the shape when it is shared or forms part of the public API.

    Takeaway

    Type the object being destructured; its bindings will then be inferred automatically.

    Where to go next

    Errors