Issue type:
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
tsc and observe no type errors in the tsc output
- Example command:
pnpm tsc script.ts
- I don't know how to properly setup the TypeScript environment, so I copy paste the
integratedscripting.d.ts contents at the top of my script which makes it work. There is almost certainly a better way. This also requires editing the integratedscripting.d.ts part to replace the declare global {var idContext: Context; } with declare var idContext: Context, as well as removing the word export from all the interfaces.
- Copy the generated code to Minecraft, it should look like
function targetBlockMod(player) {
return player.targetBlock().mod()
}
- Make a variable card targeting the
targetBlockMod function
- Use an entity reader to get an entity variable card
- Stand in front of the entity reader
- Use a Logic Programmer to
Apply the targetBlockMod function to the entity variable card
- Put the resulting card in a Display Panel
- Look at no blocks
- Observe the output crashes with a "
mod is not a property of undefined" 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.
Issue type:
Short description:
In the
integratedscripting.d.tsfile, some functions liketargetBlockmay returnundefined, 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:
tscand observe no type errors in thetscoutputpnpm tsc script.tsintegratedscripting.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.targetBlockModfunctionApplythetargetBlockModfunction to the entity variable cardmodis 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
targetBlockwas never handled, which is a bug in the typings file.Versions:
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:
<current return value> | undefinedundefined, since the docs do not say, and a lot return an empty value instead, so it will probably require manually testing every function individually.