Type-Checker doesn't respect Nil-able Methods


In nonstrict and strict Type-Checking mode, trying to call a nil-able method after conditioning will falsely propagate an error.



type Table = {
	Foo: (self: Table) -> ()?

local Table: Table = {}

function Table:Foo()

if Table.Foo then
	Table.Foo(Table) -- OK & Properly Type-Checks
	Table:Foo() -- Value of type '(any) -> ()?' could be nil

Additional Info

I am trying to make a framework that organizes codes into provider tables that act like singletons. These providers can optionally have an :OnBegin and :OnStart function inside them and when they are present, I want to run them internally.

Unfortunately, because of this bug I can’t do Provider:OnStart() and instead have to do Provider.OnStart(Provider) which comes at a small performance cost.

We’ve filled a ticket into our internal database for this issue, and will come back as soon as we have updates!

Thanks for the report!

1 Like