-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Issue type:
- ➕ Feature request
Short description:
In the integratedscripting.d.ts file, some functions like targetBlock may return undefined, but do not reflect that in their type signature, which can cause fully type valid code to crash at runtime.
Steps to reproduce the problem:
- Make a TypeScript file with the code
function targetBlockMod(player: ValueEntity) : string {
return player.targetBlock().mod()
}- Convert to JavaScript using
tscand observe no type errors in thetscoutput- Example command:
pnpm tsc script.ts - I don't know how to properly setup the TypeScript environment, so I copy paste the
integratedscripting.d.tscontents at the top of my script which makes it work. There is almost certainly a better way. This also requires editing theintegratedscripting.d.tspart to replace thedeclare global {var idContext: Context; }withdeclare var idContext: Context, as well as removing the wordexportfrom all the interfaces.
- Example command:
- Copy the generated code to Minecraft, it should look like
function targetBlockMod(player) {
return player.targetBlock().mod()
}- Make a variable card targeting the
targetBlockModfunction - Use an entity reader to get an entity variable card
- Stand in front of the entity reader
- Use a Logic Programmer to
ApplythetargetBlockModfunction to the entity variable card - Put the resulting card in a Display Panel
- Look at no blocks
- Observe the output crashes with a "
modis not a property ofundefined" error (Just the output of the variable card should crash with a red X, Minecraft/the server should not crash)
Expected behaviour:
The TypeScript code should not have passed with no errors, as the possibly undefined output of targetBlock was never handled, which is a bug in the typings file.
Versions:
- This mod: integratedscripting-1.12.1-neoforge-1.0.17-259
- Minecraft: 1.21.1
- Mod loader version: NeoForge 21.1.168
- Modpack: ATM10 2.47
Note: I did not report the bug to ATM10/do any standalone testing since given this is an issue with the typings file generation I don't see how it would be affected by anything else in the pack.
Log file:
A couple more notes:
- My suggested fix for this would be to change the signature of those functions to
<current return value> | undefined - I have not looked through all the ID functions to see which ones could return
undefined, since the docs do not say, and a lot return an empty value instead, so it will probably require manually testing every function individually.
Metadata
Metadata
Assignees
Type
Projects
Status
Accepted (To Do)