Luau Typechecking on OOP: type 'self' does not have key '[method name here]'

Hello! I am currently trying out the new --!strict feature of Luau on an OOP module. It is going good so far, but I’m having this annoying issue where it says type ‘self’ does not have key ‘PickUp’. The script is to be found here:

local module = {}

--// Settings
local DefaultPrimaryPartIdentifiers = {
	-- Not important

--// Auxilary Functions
local function IdentifyPrimaryPart(Model: Model): BasePart?
	-- Not important

--// Module
function Model)
	assert(typeof(KeyModel) == "Instance", "Given KeyModel is not an Instance!")
	assert(KeyModel:IsA("Model"), "Given KeyModel is not a Model!")
	local PrimaryPart = IdentifyPrimaryPart(KeyModel)
	assert(PrimaryPart, "Couldn't find a PrimaryPart for KeyModel.")
	local self = setmetatable({}, module)
	self.Model = KeyModel
	local ProximityPrompt ="ProximityPrompt")
	ProximityPrompt.ActionText = "Pick Up"
	ProximityPrompt.KeyboardKeyCode = Enum.KeyCode.E
	ProximityPrompt.HoldDuration = 0
	ProximityPrompt.MaxActivationDistance = 8
	ProximityPrompt.ObjectText = "Key"
	ProximityPrompt.Parent = PrimaryPart
		self:PickUp(Player) -- Line of warning
	return self

function module:PickUp(Player: Player)
	-- Not important

return module

Here on the image is shows the warning. Well, anyone with experience on OOP knows that this is possible and will work. However, Luau typechecking does not recognize PickUp as a method of ‘self’.

I know that module.PickUp(self, Player) is a possible solution, but it looks rather unnatural and dissatisfying to look at. Does anyone know a way of keeping the same coding aesthetic but fixing the warning at the same time?

Help is appreciated!

That has nothing to do with it.

1 Like

Try setting the module’s __index value

Using a colon is syntactic sugar.

local T = {}

function T.Something(self, b)
	for Key, _ in pairs(self) do

	return b + b

-- Dot

T.Something(T, 10) -- Needs T to use self

-- Colon

T:Something(10) -- the "self" parameter is automatically supplied with T.

Haha how dumb of me. I forgot to add that.