ECMAScript icon indicating copy to clipboard operation
ECMAScript copied to clipboard

Typescript complains when trying to use operators such as += on Vector2

Open ceuk opened this issue 3 years ago • 3 comments

e.g. Something like this:

 this.position += new godot.Vector2(this.velocity * delta)

Will generate the following error in typescript:

Operator '+=' cannot be applied to types 'godot.Vector2' and this.position + 'godot. 
—————————————————
The left-hand side of an arithmetic operation must be of type godot.register_property 'any', 'number', 'bigint' or an enum type. 

Is this an error on my part of a problem wit the type declaration?

ceuk avatar Mar 24 '21 08:03 ceuk

specifying any types for the Vector2 properties in question gets rid of the error, but kind of defeats the purpose of using typescript to begin with

ceuk avatar Mar 24 '21 08:03 ceuk

This needs to modify how tsc's type checker is implemented, which is out of scope for this project, likely. Project like Deno suffer similar problems as well because Deno uses TS slightly differently from NodeJS.

If this project doesn't fork tsc, an acceptable workround for me is to omit this kind of errors in the Godot VS code plugin. (override TS language server's diagnostic output)

CreatCodeBuild avatar Jun 07 '21 05:06 CreatCodeBuild

https://github.com/GodotExplorer/ECMAScript/issues/33

scgm0 avatar Mar 07 '22 17:03 scgm0