question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object.defineProperty doesn't define properties on 'this'

See original GitHub issue
// @ts-check

class C {
  constructor() {
    Object.defineProperty(this, "x", { value: "hello" });

    this.x.toLowerCase();
  }
}

Expected: No error. Actual: Property 'x' does not exist on type 'C'.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DanielRosenwassercommented, Oct 29, 2019

@tokland This is about JavaScript analysis, not TypeScript.

1reaction
akornatskyycommented, Dec 26, 2020

You need to add definite assertion assignment to property ‘x: string’.

class C {
  x!: string;  // definite assertion
  constructor() {
    Object.defineProperty(this, 'x', {value: 'hello'});
    this.x.toLowerCase();
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.defineProperty() - JavaScript - MDN Web Docs
When the property specified doesn't exist in the object, Object.defineProperty() creates a new property as described.
Read more >
Why does object.defineproperty not add the property to the ...
Object.defineProperty defines non enumerable properties unless the descriptor overrides the default value ( false ) for enumerable . var ...
Read more >
Object.defineProperty() - Javascript - CodeProject Reference
The Object.defineProperty() method defines a new property directly on an object, or modifies an existing property on an object, and returns the object....
Read more >
11 Properties: assignment vs. definition - Exploring JS
There are two ways of creating or changing a property prop of an object obj : Assigning: obj.prop = true; Defining: Object.defineProperty(obj, '',...
Read more >
JavaScript Object defineProperty() Method - Javatpoint
The Object.defineProperty() method defines a new property directly on an object and returns the object. To change the flags, we can use Object.defineProperty....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found