Skip to content

Some functions may return undefined but are not typed to reflect it #42

@MeGaGiGaGon

Description

@MeGaGiGaGon

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:

  1. Make a TypeScript file with the code
function targetBlockMod(player: ValueEntity) : string {
    return player.targetBlock().mod()
}
  1. 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.
  2. Copy the generated code to Minecraft, it should look like
function targetBlockMod(player) {
    return player.targetBlock().mod()
}
  1. Make a variable card targeting the targetBlockMod function
  2. Use an entity reader to get an entity variable card
  3. Stand in front of the entity reader
  4. Use a Logic Programmer to Apply the targetBlockMod function to the entity variable card
  5. Put the resulting card in a Display Panel
  6. Look at no blocks
  7. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Accepted (To Do)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions