Re: [sensors] Undefined values makes GS a pain to work with using TypeScript

This is what you need to do today to get TS to shut up (and my PRs to pass so they can be merged :))

```
        update(reading: Accelerometer | Gyroscope | Magnetometer) {
            if (!this.timestamp || !this.x || !this.y || !this.z) {
                this.x = reading.x;
                this.y = reading.y;
                this.z = reading.z;
                this.timestamp = reading.timestamp;
                return;
            }

            if (!reading.timestamp || !reading.x || ! reading.y || !reading.z) {
                return;
            }

            const dt = reading.timestamp - this.timestamp / 1000;
            this.timestamp = reading.timestamp;

            const alpha = this.cutoff / (this.cutoff + dt);
            this.x = this.x + alpha * (reading.x - this.x);
            this.y = this.y + alpha * (reading.y - this.y);
            this.z = this.z + alpha * (reading.z - this.z);
        }
```

-- 
GitHub Notification of comment by kenchris
Please view or discuss this issue at https://github.com/w3c/sensors/issues/269#issuecomment-330179284 using your GitHub account

Received on Monday, 18 September 2017 10:17:42 UTC