Typescript compiler errors in my scripts when building - how to fix (TSC)

I got errors when building but these all seems to be just warnings. Is this intentional?

Original Post on Discord

by user 334342083445784576

Yes - I mean you can configure your tsconfig to ignore those but I would recommend you check what the error says (these are typescript compiler errors, they may or may not be bad - depends on your project)

yes, all these variables are set through serialisation from the unity site. So setting them null or undefinied in the script seemed okay for me.

by user 334342083445784576

If you are sure those are OK you can always add @ts-ignore above typescript errors like these in your scripts.

Or in the case of “no initializer” its something like

myVariable : Object3D;

and the error says you should write one of these:

myVariable?:Object3D; // its undefined by default
myVarialbe!:Object3D; // suppress that its not initialized telling the compiler this is always assigned;
myVariable:Object3D|null = null;

and never used can be fixed by starting the variable with an underscore for example :slightly_smiling_face:

e.g. function test(_myString:string) { ....

Changed the channel name: Typescript compiler errors in my scripts when building - how to fix (TSC)

hmm, //@ts-ignore works but not very nice code style I guess.
Setting the variables to undefined or null does not help when I want to assign them, e.g.

by user 334342083445784576

cameraAnchor: Object3D = new Object3D() does not work, already tried it.

by user 334342083445784576

what do you mean by “when i want to assign them” ?

if you know the variable is not null then you can write myVariable! : Object3D

otherwise you need to check in your code below that the variable is not undefined. E.g.



if(!this.myVariable) return;


if(this.myVariable === undefined) return;

oh man, okay you’re right. I feel like an amateur :smile:

by user 334342083445784576

All good :slightly_smiling_face: been there :smile:

last question, when I’m using import { Object3D } from "three";
in the script, the compiler also fails with

Error: ‘default’ is not exported by …/…/Library/PackageCache/com.needle.engine@2.59.2-pre/package~/node_modules/three/build/three.module.js, imported by src/scripts/NeedleCameraControl.ts

by user 334342083445784576

Removing the line, hitting the play button works, but production build fails.

by user 334342083445784576

Does it give you a line? Are you using default export ?

the import should be fine

yes, default vite export.

by user 334342083445784576

Havent seen this error before - can you share your script ?