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.

ES6 and Object.defineProperties issue

See original GitHub issue

lets say i have the following class:

class Object3D extends EventDispatcher {

	constructor() {

		super();

		const quaternion = new Quaternion();

		Object.defineProperties( this, {
			quaternion: {
				configurable: true,
				enumerable: true,
				value: quaternion
			}
		} );
      }

       onRotationChange() {
		this.quaternion.setFromEuler(........);
	 }
 }

and the following warning:

core/Object3D.js:123:7: WARNING - [JSC_INEXISTENT_PROPERTY] Property quaternion never defined on Object3D
  123| 		this.quaternion.setFromEuler();
       		   ^^^^^^^^^^

I have no idea what i do wrong, maybe i missed something ?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
nreid260commented, Jan 13, 2021

Just want to add, the compiler recognizes properties creates by Object.defineProperties during optimizations, but not during typechecking. As such, we believe things are working as intended.

That distinction might feel arbitrary, but optimizations generally require less information about properties (usually just “does this name exist somewhere in the program?”) so it’s easier to add support. Recognizing them during typechecking is more nuanced.

Additionally, optimization failure can cause runtime behaviour issues, so we need to be very conservative, and often silently cancel optimizations when something might be wrong. In contrast, typechecking failure is a compile-time problem, so we can make it more user visible, and defer to the user (via suppressions or annotations) when we get false positives.

1reaction
treblereelcommented, Dec 29, 2020

@ctjlewis thanks for your clarification, so it means closure ignores Object.defineProperties/Object.defineProperty ? Ok, i am working on three.js and i didn’t want to change the code too much but looks like i have no choice to make it closure compatible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.defineProperties() - JavaScript - MDN Web Docs
The Object.defineProperties() method defines new or modifies existing properties directly on an object, returning the object.
Read more >
Object.defineProperty sometimes throws - Stack Overflow
I am playing with ES6 classes and non-writable properties. As an example, I have the following code. I am running it under node...
Read more >
JavaScript ES5: Meet the Object.defineProperty() Method
This tutorial explains how and why to use the Object.defineProperty() method in JavaScript ES5. It may sound like a complicated thing... until you...
Read more >
Object.defineProperty in class constructor - Google Groups
The compiler does not understand these constructs well. ES6 getter and setters are transformed to Object.defineProperties(…) through transpilation. Currently, ...
Read more >
14. New OOP features besides classes - Exploring JS
Object.setPrototypeOf(obj, proto). 14.4. Traversing properties in ES6 ... There is also a way to concisely define properties whose values are generator ...
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