Skip to content

    ↑↓ move · ⏎ open · esc close

    TS2339

    No such property

    Property 'b' does not exist on type '{ a: number; }'.

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

    You reached for a property the type does not have. Often the type is right and the spelling is wrong; sometimes the type is narrower than the value really is.

    Reproduction

    declare const o: { a: number }
    
    o.b

    The build asserts this emits exactly this code.

    Why the compiler says this

    Object types are exact about what they contain. The compiler is not saying the property is missing at run time — it may well be there — but that nothing in the program said it would be, so nothing can be assumed about it. When the value came from JSON or an API, this error is usually correct and the type is the thing that is lying.

    Fixes

    1. 01
      declare const o: { a: number; b: string }
      
      o.b

      Add it to the type, if the value really carries it. The type is a description; make it describe the truth.

    2. 02
      declare const o: { a: number; b?: string }
      
      if (o.b !== undefined) {
        o.b.trim()
      }

      Or mark it optional and check for it, if it is sometimes there. This is the shape that matches reality for anything parsed rather than constructed.

    Takeaway

    This error is a disagreement between your type and your value. Decide which one is wrong before you change either.

    Errors