Closed ZZZank closed 3 months ago
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
})
It might be possible to make the lambda type to be aware of the context to infer correct types according to the position in the type later, but that might not be of a high priority.
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:
will produce a result like this:
My expectation is that at least the second lambda should acts like regular functions(recive "duck" and return "solid")