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.

TS: Vector3 interface not descriptive enough to support this valid usage

See original GitHub issue
Description of the problem

The following code works, but TypeScript does not compile with the present Vector3.d.ts

  // vector between center of head and center of ear
  const earVector = new THREE.Vector3(1.44, 0.6, -0.3);

  const leftEar = new THREE.SphereGeometry(1, 32, 32).applyMatrix4(new THREE.Matrix4().makeScale(0.4, 0.4, 0.25));
  const rightEar = leftEar.clone();

  leftEar.translate(...earVector.toArray());
  earVector.x = -earVector.x;
  rightEar.translate(...earVector.toArray());

BUG (compile error): Expected 3 arguments, but got 0 or more. ts(2556)

EXPECTED: Given that the code behaves as expected, I would expect it to compile. (I would also expect the aesthetics of this use of the spread operator to divide opinion)

Three.js version
  • Dev
  • r116
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, …)

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
donmccurdycommented, May 18, 2020

I’ve used this syntax elsewhere:

export type vec2 = [number, number];

export type vec3 = [number, number, number];

export type vec4 = [number, number, number, number];

export type mat3 = [
	number, number, number,
	number, number, number,
	number, number, number,
];

export type mat4 = [
	number, number, number, number,
	number, number, number, number,
	number, number, number, number,
	number, number, number, number,
];

There is no list/tuple distinction at runtime, this is just for typechecking.

4reactions
gkjohnsoncommented, May 5, 2020

From this stackoverflow answer it sounds like you could define fixed array types of a specific length and reuse them but I haven’t tested it:

// ReusableTypes.d.ts
export type Length3Array = [ number, number, number ];
export type Length4Array = [ number, number, number, number ];
export type Length16Array = [ /* ... */ ];

// Vector3.d.ts
class Vector3 {

    // ...

    toArray() : Length3Array;

}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handbook - Interfaces - TypeScript
Class Types​​ Interfaces describe the public side of the class, rather than both the public and private side. This prohibits you from using...
Read more >
[Released] OneJS: Typescript + React (JSX) for Unity
OneJS is a Javascript Engine specifically designed for Unity. It is lightweight, performant, pure C# based, has first-class Typescript support, ...
Read more >
Understanding and using interfaces in TypeScript
A class or function can implement an interface to define the implementation of the properties as defined in that interface. Over 200k developers ......
Read more >
Non-Volatile Memory Host Controller Interface - NVM Express
THE AUTHORS DO NOT. WARRANT OR REPRESENT THAT SUCH USE WILL NOT INFRINGE ANY SUCH RIGHTS. THE. PROVISION OF THIS SPECIFICATION TO YOU...
Read more >
PCI Express (PCIe) for KeyStone Devices User's Guide (Rev. D)
Updated the description of BAR mask register usage (Page 2-16) ... The PCI Express module does not support the following features:.
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