Skip to content
TS2749

    ↑↓ move · ⏎ open · esc close

    TS2749

    Value used as a type

    'widget' refers to a value, but is being used as a type here. Did you mean 'typeof widget'?

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

    A runtime variable was written in type space; use `typeof` to ask for the type of that value.

    Reproduction

    const widget = { id: 1 }
    
    type Copy = widget

    The build asserts this emits exactly this code.

    Why the compiler says this

    Names do not automatically cross from value space into type space. The type-query form of `typeof` is the explicit bridge: it asks the checker to capture the static type of an existing value without running JavaScript’s `typeof` operator.

    Fixes

    1. 01
      const widget = { id: 1 }
      
      type Copy = typeof widget

      Use a type query when the value should be the source of truth.

    2. 02
      type Widget = { id: number }
      
      const widget: Widget = { id: 1 }

      Declare the type first when the contract should govern several values.

    Takeaway

    Use `typeof value` in a type position; bare value names remain runtime expressions.

    Where to go next

    Errors