Typechecker requires pcall to pass nil-values for nullable parameters

Use any ROBLOX method with nullable parameters or create your own function with nullable parameters:

local function Add(a: number, b: number?): number
	return a + (b or a)
end

Using pcall to execute the function:

pcall(Add, 1)

not providing the b parameter will result in a type error:

In order to avoid the type error, a nil value has to be passed:

pcall(Add, 1, nil)

image

Expected behavior

Nullable parameters are optional and should be detected as optional.
Not providing an optional parameter should not cause a type error.

Hi there! This appears to be the type system working as expected, and you will need to provide nil to pcall, even when an argument is optional. We would need to carve out a special case for pcall in the type system for things to work as you describe, and this is not unfortunately currently on our roadmap.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.