Probejs without VSCode? Typescript compilation errors
UltraBlackLinux opened this issue · 18 comments
Is it somehow possible to get this plugin's functionality to work without VSCode? I'm using helix, and the default typescript language server really should be enough to get this working.
The typescript headers in kubejs are pretty much unusable, they have syntax errors everywhere. The way you're doing it, by just parsing some list of types and stuff into vscode-specific config files doesn't make it possible to use this on other editors.
Is it possible that you streamline the process so it can actually be used just with the ts/js language server?
Thanks!
Try to add "skipLibCheck": true
in your jsconfig.json
and see if it works.
The files generated should be editor-agnostic. Your TS server is throwing out errors because they are incompatible with TS's own type system—and they will never be. TypeScript is different from Java.
Files generated for VSCode's own snippet usage (e.g., things in .vscode
) have nothing to do with the actual types generated, you should still get complete completions/type-checking etc when you work on other editors because those are standard .d.ts
files and the jsconfig.json
is set up.
Your TS server is throwing out errors because they are incompatible with TS's own type system—and they will never be. TypeScript is different from Java.
Huh? So the headers are pretty much just a hacky way to get typing to work? skipLibCheck will not be the solution though. Even trying to build a command I get errors for wrong return types and stuff. The example code for a command on the wiki is wrong according to the header files.
Those are called type declaration files
, they are not "header files" like in C++, they are only for describing types that should exist (but not present now) at runtime.
Huh? So the headers are pretty much just a hacky way to get typing to work? skipLibCheck will not be the solution though. Even trying to build a command I get errors for wrong return types and stuff.
The .d.ts
files generated at least reflect most of the types, classes, and their methods, params, and return types faithfully; skipLibCheck
is for making your TS server complain less.
The example code for a command on the wiki is wrong according to the header files.
There are a lot of example codes from the wiki, and things might be outdated or just mismatched; you can't say what is right or what is wrong without actually trying them.
No it's not that they're out of date or anything. The example code on the wiki runs with no complaint, but I get typing errors in there according to the declaration/header/whatever files.
Edit: This: https://kubejs.com/wiki/tutorials/chat#command-registry-event
Then I can do nothing about them, the type is what Java Reflection API can give me, and I tried my best to adapt them into how JS/TS parses things, if your editor insists on running things and having strict checks like what an actual TypeScript server with skipLibCheck: false
on without respecting the option is true
, then I can do nothing because that's your editor's behavior.
Or you should really post what are those syntax errors you get, because I won't get syntax errors on my machine, otherwise I will fix them before releasing the mod.
Then I can do nothing about them, the type is what Java Reflection API can give me, and I tried my best to adapt them into how JS/TS parses things, if your editor insists on running things and having strict checks like what an actual TypeScript server with
skipLibCheck: false
on without respecting the option istrue
, then I can do nothing because that's your editor's behavior.Or you should really post what are those syntax errors you get, because I won't get syntax errors on my machine, otherwise I will fix them before releasing the mod.
Again the problem is not that the typescript header files are bogus (which I guess they are), but the problem is that they want types that just don't make any sense there. I can enable SkibLipCheck all day, but the syntax errors in my code will persist.
.executes(c => fly(Arguments.PLAYER.getResult(c, 'target'))) // the return value (0, 1) is apparently not valid. It wants some weird class. Just gave up on kubejs so I don't have the exact error here, but there's definitely something wrong with the headers
You can only enable skipLibCheck
here because you are working on JS, not TS. And KubeJS
uses a modified Mozilla Rhino
, which is not any standard JS implementation (like how it has arrow functions but doesn't have classes). Not to mention it has a lot of random type wrappers set or removed almost every major version that I can't keep track of.
You can only enable skipLibCheck here because you are working on JS, not TS
I tried TS too, same errors, and tsc took a good long 15 minute dump into my terminal before I ultimately killed it. SkipLibCheck would have helped, but the errors would've been there regardless
Those errors aren't actual errors due to mistyping or whatever the thing you're caring about, they are just because the type system in TypeScript is NOT fully compatible with Java's, and I can't make it fully cope.
A very common problem is that, what do you think an interface
is in TypeScript? An interface is a class in Java, so everytime an arrow function/lambda is passed to a @FunctionalInterface
, Java knows about that and implements default methods from the original interface class because there is a class.
But for TypeScript, the interface is just a protocol - it won't exist at runtime, so anything that is declared as an interface, and any type that accepts an interface should implement everything that the interface declared.
And TypeScript doesn't have multiple inheritance like in Python or other languages, so for a class it can only extend one class and implement many interfaces, I can never make such thing compatible.
Do they? I don't think they have a runtime type generator reading from all the current classes loaded in game.
You might wanna look at some of the work that has been done for JSMacros. They've already solved a lot of issues like that
There have been some efforts to generate typescript definition files from source, with good success I might add
They can have nice built method docs because those functions are well written and defined in a way that won't hurt much - and for most of the time you won't need to step out of the libraries it provides. But as Rhino itself naturally gets quite wild when dealing with all kinds of things, KubeJS itself tends to implement new features by mixin into Java classes rather than creating abstraction layer between actual class and things in Java, I can do nothing, I can only try to reshape the Java's type system into something that can fit in a not-that-strict JS environment. And it works in VSCode, I have no knowledge, no time and no energy to do more.