types of param/return in a lambda looks suspicious
ZZZank opened this issue ยท 2 comments
lambdas seems to be receiving a "solid type" param and returns a duck type, which does not match the behaviour of regular functions and methods(recive "duck" and return "solid")
E.g. These codes:
ProbeEvents.modifyClass((event) => {
const ingr = $Types.typeMaybeGeneric($Ingredient)
const lam = $Types.lambda().param("someArg", ingr).returnType(ingr).build()
event.modify($TypingModificationEventJS, (file) => {
file.addCode(
$Statements.method("exampleMethod")
.param("lamArg", lam)
.returnType(lam)
.build()
)
})
})
will produce a result like this:
function exampleMethod(
lamArg: (someArg: $Ingredient) => $Ingredient$$Type
): (someArg: $Ingredient) => $Ingredient$$Type
My expectation is that at least the second lambda should acts like regular functions(recive "duck" and return "solid")
Use .method()
before any param
call to make a lambda type to type like a regular method.
Normally we expect the lambda type to be something implemented by the JS side (e.g. Consumer<Object>
=> (object)=> {}
), so the lambda will receive concrete type and return duck type by default, so the following will work:
function testMethod(arg: (entity: $Entity) => $ItemStack$$Type){
...
}
testMethod(entity => {
console.info(entity.x) // We have completions here
return 'minecraft:apple' // and here, too
})