Issue: Typing Bug
Severity: Moderate, as it impedes my usage of Luau.
Description: There seems to be a typing bug requiring the optional typing parameter. When creating an OOP class, and then defining a type for said OOP class, the type checker seems to has an aneurysm in a very specific edge case. When there is an exported type of the object, it errors with a “Free types leaked into this module’s public interface.”
All it requires seems to be having a value by default be a function.
Steps to Reproduce:
- Create an OOP class using metatables.
- Have one of the arguments for the constructor be an optional type.
- Set a value in the object to the argument if the argument is not nil.
- If the argument is nil, then set the value to a default function.
- Export a type of the objects constructor, with no arguments.
Repro Code:
--!strict
local object = {}
object.__index = object
type Predicate = (any) -> boolean
function object.new(a: Predicate?)
local self = setmetatable({}, object)
self.compare = a or function(obj)
return true
end
return self
end
export type object_Type = typeof(object.new())
return object