#Why is there no `Component` class that is covariant with strings for registry functions?

17 messages · Page 1 of 1 (latest)

south granite
#

Basically the title. I am using typescript with kubejs and I have been casting strings as any but I would like to figure this out so I can have accurate type checking.

tranquil canyonBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

south granite
#

Ok maybe the title is misleading, I am just wondering why the function does not accept a type like how recipe functions accept type InputItem_ that allows for strings

#

let me see if I can edit it

#

Why is there no Component class that is covariant with strings for registry functions?

left steppe
#

Actually, that is MutableComponent typing that isn't assignable to Component typing

#

Though MutableComponent is extending Component

#

The issue is that Internal.Component is different from globalThis.Component

#

This is why: MutableComponent incorrectly implements Component, that's a ProbeJS bug

#

If it were correctly implemented (aka all the methods from the Component interface were in MutableComponent), then MutableComponent would be assignable to Component, as it contains all the methods of Component (TypeScript uses structural typing)

#

If you want to fix, copy over Internal.Component typing and in a custom type definition file (/probe/user/custom.d.ts or whatever):

declare namespace Internal {
  // @ts-expect-error Incompatible `composite` typing
  interface MutableComponent extends com.mojang.brigadier.Message, Internal.FormattedText {
  // Stuff copied from Internal.Component
  // Remove `abstract` as `abstract` can't be in interfaces, yet ProbeJS generates typings with that keyword
  }
}
#

Then MutableComponent should be assignable to Component.

south granite
#

Btw I've been stalking your messages in the probejs channel. You've helped me out a lot and I just want to thank you for that.

#

I've got a lot of probejs hacks in my build script (written in bash) and only half of them actually work 😭 so I might want to rewrite it in javascript or something

#

Since this seems a bit more complicated than just file concatenation and string manipulation